Guarantee single thread execution order

This commit is contained in:
M66B 2020-03-08 12:32:52 +01:00
parent ee35150455
commit e8b4038c12
1 changed files with 4 additions and 1 deletions

View File

@ -127,6 +127,7 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Pattern;
import static android.os.Process.THREAD_PRIORITY_BACKGROUND;
@ -190,6 +191,8 @@ public class Helper {
0L, TimeUnit.MILLISECONDS,
new PriorityBlockingQueue<Runnable>(10, new PriorityComparator()),
factory) {
private final AtomicLong sequenceId = new AtomicLong();
@Override
protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T value) {
RunnableFuture<T> task = super.newTaskFor(runnable, value);
@ -198,7 +201,7 @@ public class Helper {
((PriorityRunnable) runnable).getPriority(),
((PriorityRunnable) runnable).getOrder());
else
return task;
return new PriorityFuture<>(task, 0, sequenceId.getAndIncrement());
}
};
else