aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/utils/ReplacingSerialSingleThreadExecutor.java
blob: 79e5126b2bb1fac53d7480c4a5d8f1b9776e8df6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package de.pixart.messenger.utils;

public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecutor {

    public ReplacingSerialSingleThreadExecutor(String name) {
        super(name);
    }

    @Override
    public synchronized void execute(final Runnable r) {
        tasks.clear();
        if (active instanceof Cancellable) {
            ((Cancellable) active).cancel();
        }
        super.execute(r);
    }

    public synchronized void cancelRunningTasks() {
        tasks.clear();
        if (active instanceof Cancellable) {
            ((Cancellable) active).cancel();
        }
    }
}