Guarantee single thread execution order

pull/175/head
M66B 5 years ago
parent ee35150455
commit e8b4038c12

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

Loading…
Cancel
Save