2016-05-31 15:20:21 +00:00
|
|
|
package eu.siacs.conversations.utils;
|
|
|
|
|
|
|
|
public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecutor {
|
|
|
|
|
2018-04-26 11:22:31 +00:00
|
|
|
public ReplacingSerialSingleThreadExecutor(String name) {
|
|
|
|
super(name, false);
|
|
|
|
}
|
|
|
|
|
2018-03-18 15:46:50 +00:00
|
|
|
public ReplacingSerialSingleThreadExecutor(boolean prepareLooper) {
|
|
|
|
super(ReplacingSerialSingleThreadExecutor.class.getName(), prepareLooper);
|
|
|
|
}
|
2016-05-31 15:20:21 +00:00
|
|
|
|
2018-03-18 15:46:50 +00:00
|
|
|
@Override
|
|
|
|
public synchronized void execute(final Runnable r) {
|
|
|
|
tasks.clear();
|
2018-04-26 11:22:31 +00:00
|
|
|
if (active != null && active instanceof Cancellable) {
|
|
|
|
((Cancellable) active).cancel();
|
|
|
|
}
|
2018-03-18 15:46:50 +00:00
|
|
|
super.execute(r);
|
|
|
|
}
|
2018-04-26 15:02:31 +00:00
|
|
|
|
|
|
|
public synchronized void cancelRunningTasks() {
|
|
|
|
tasks.clear();
|
|
|
|
if (active != null && active instanceof Cancellable) {
|
|
|
|
((Cancellable) active).cancel();
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 15:20:21 +00:00
|
|
|
}
|