anotherim/src/main/java/eu/siacs/conversations/utils/ReplacingSerialSingleThreadExecutor.java

25 lines
539 B
Java
Raw Normal View History

package eu.siacs.conversations.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();
}
}
}