diff --git a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusThreadPoolExecutor.java b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusThreadPoolExecutor.java index 7e7cadad2a..f39d1261e8 100644 --- a/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusThreadPoolExecutor.java +++ b/modules/react-native-status/android/src/main/java/im/status/ethereum/module/StatusThreadPoolExecutor.java @@ -2,9 +2,13 @@ package im.status.ethereum.module; import java.util.concurrent.*; +/** Uses an unbounded queue, but allows timeout of core threads + * (modified case 2 in + * https://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadPoolExecutor.html ) */ public class StatusThreadPoolExecutor { private static final int NUMBER_OF_CORES = Runtime.getRuntime().availableProcessors(); + private static final int THREADS_TO_CORES_RATIO = 100; private static final int KEEP_ALIVE_TIME = 1; private static final TimeUnit KEEP_ALIVE_TIME_UNIT = TimeUnit.SECONDS; @@ -15,11 +19,14 @@ public class StatusThreadPoolExecutor { mQueue = new LinkedBlockingQueue<>(); mThreadPool = new ThreadPoolExecutor( - NUMBER_OF_CORES, - NUMBER_OF_CORES, + THREADS_TO_CORES_RATIO * NUMBER_OF_CORES, + THREADS_TO_CORES_RATIO * NUMBER_OF_CORES, KEEP_ALIVE_TIME, KEEP_ALIVE_TIME_UNIT, mQueue); + + // Allow pool to drain + mThreadPool.allowCoreThreadTimeOut(true); } /** Pugh singleton */