mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-26 22:20:20 +00:00
Fix bounded-io thread pool race condition preventing additional thread starts.
This commit is contained in:
committed by
Michelle Tang
parent
3fee68e33e
commit
f1614ec772
@@ -5,12 +5,12 @@ import android.os.Process;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.signal.core.util.LinkedBlockingLifoQueue;
|
||||
import org.signal.core.util.ThreadUtil;
|
||||
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.SynchronousQueue;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
@@ -52,7 +52,7 @@ public final class SignalExecutors {
|
||||
maxThreads,
|
||||
timeoutSeconds,
|
||||
TimeUnit.SECONDS,
|
||||
new LinkedBlockingQueue<Runnable>() {
|
||||
new SynchronousQueue<>() {
|
||||
@Override
|
||||
public boolean offer(Runnable runnable) {
|
||||
if (isEmpty()) {
|
||||
@@ -74,14 +74,6 @@ public final class SignalExecutors {
|
||||
return threadPool;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an executor that prioritizes newer work. This is the opposite of a traditional executor,
|
||||
* which processor work in FIFO order.
|
||||
*/
|
||||
public static ExecutorService newFixedLifoThreadExecutor(String name, int minThreads, int maxThreads) {
|
||||
return new ThreadPoolExecutor(minThreads, maxThreads, 0, TimeUnit.MILLISECONDS, new LinkedBlockingLifoQueue<>(), new NumberedThreadFactory(name, ThreadUtil.PRIORITY_BACKGROUND_THREAD));
|
||||
}
|
||||
|
||||
public static HandlerThread getAndStartHandlerThread(@NonNull String name, int priority) {
|
||||
HandlerThread handlerThread = new HandlerThread(name, priority);
|
||||
handlerThread.start();
|
||||
|
||||
Reference in New Issue
Block a user