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) {
|
2018-10-26 22:32:09 +00:00
|
|
|
super(name);
|
2018-03-18 15:46:50 +00:00
|
|
|
}
|
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-10-26 22:32:09 +00:00
|
|
|
if (active instanceof Cancellable) {
|
2018-04-26 11:22:31 +00:00
|
|
|
((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();
|
2018-10-26 22:32:09 +00:00
|
|
|
if (active instanceof Cancellable) {
|
2018-04-26 15:02:31 +00:00
|
|
|
((Cancellable) active).cancel();
|
|
|
|
}
|
|
|
|
}
|
2016-05-31 15:20:21 +00:00
|
|
|
}
|