Fixes #5293: Messaging/transacting take too long to be processed
Signed-off-by: Pedro Pombeiro <pombeirp@users.noreply.github.com>
This commit is contained in:
parent
9ddcbe863a
commit
3f73c5545d
|
@ -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 */
|
||||
|
|
Loading…
Reference in New Issue