conversations-classic/src/main/java/eu/siacs/conversations/utils/ReplacingSerialSingleThreadExecutor.java

29 lines
732 B
Java
Raw Normal View History

package eu.siacs.conversations.utils;
public class ReplacingSerialSingleThreadExecutor extends SerialSingleThreadExecutor {
public ReplacingSerialSingleThreadExecutor(String name) {
super(name, false);
}
public ReplacingSerialSingleThreadExecutor(boolean prepareLooper) {
super(ReplacingSerialSingleThreadExecutor.class.getName(), prepareLooper);
}
@Override
public synchronized void execute(final Runnable r) {
tasks.clear();
if (active != null && active instanceof Cancellable) {
((Cancellable) active).cancel();
}
super.execute(r);
}
public synchronized void cancelRunningTasks() {
tasks.clear();
if (active != null && active instanceof Cancellable) {
((Cancellable) active).cancel();
}
}
}