From 3f73c5545de18bf607763926d5bb841ec69ceabc Mon Sep 17 00:00:00 2001 From: pacamara Date: Fri, 17 Aug 2018 12:00:14 +0100 Subject: [PATCH] Fixes #5293: Messaging/transacting take too long to be processed Signed-off-by: Pedro Pombeiro --- .../ethereum/module/StatusThreadPoolExecutor.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) 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 */