Added maximum queue size to avoid outofmemory
This commit is contained in:
parent
816e9db448
commit
894351e633
@ -13,6 +13,8 @@ import org.jetbrains.annotations.Nullable;
|
|||||||
|
|
||||||
public class BoundedExecutorService {
|
public class BoundedExecutorService {
|
||||||
|
|
||||||
|
private static final int MAX_BLOCKING_QUEUE_SIZE = 50000;
|
||||||
|
|
||||||
private BoundedExecutorService() {
|
private BoundedExecutorService() {
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -34,7 +36,7 @@ public class BoundedExecutorService {
|
|||||||
TimeUnit unit,
|
TimeUnit unit,
|
||||||
ThreadFactory threadFactory,
|
ThreadFactory threadFactory,
|
||||||
@Nullable BiConsumer<Boolean, Integer> queueSizeStatus) {
|
@Nullable BiConsumer<Boolean, Integer> queueSizeStatus) {
|
||||||
return createCustom(0, corePoolSize, maxPoolSize, keepAliveTime, unit, threadFactory, Duration.ofDays(100000), queueSizeStatus, new LinkedBlockingQueue<>());
|
return createCustom(0, corePoolSize, maxPoolSize, keepAliveTime, unit, threadFactory, Duration.ofDays(100000), queueSizeStatus, new LinkedBlockingQueue<>(MAX_BLOCKING_QUEUE_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExecutorService createUnbounded(
|
public static ExecutorService createUnbounded(
|
||||||
@ -67,7 +69,7 @@ public class BoundedExecutorService {
|
|||||||
TimeUnit unit,
|
TimeUnit unit,
|
||||||
ThreadFactory threadFactory,
|
ThreadFactory threadFactory,
|
||||||
@Nullable BiConsumer<Boolean, Integer> queueSizeStatus) {
|
@Nullable BiConsumer<Boolean, Integer> queueSizeStatus) {
|
||||||
return createCustom(maxQueueSize, corePoolSize, maxPoolSize, keepAliveTime, unit, threadFactory, Duration.ofDays(100000), queueSizeStatus, new LinkedBlockingQueue<>());
|
return createCustom(maxQueueSize, corePoolSize, maxPoolSize, keepAliveTime, unit, threadFactory, Duration.ofDays(100000), queueSizeStatus, new LinkedBlockingQueue<>(MAX_BLOCKING_QUEUE_SIZE));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ExecutorService create(
|
public static ExecutorService create(
|
||||||
@ -99,6 +101,7 @@ public class BoundedExecutorService {
|
|||||||
queue,
|
queue,
|
||||||
threadFactory
|
threadFactory
|
||||||
);
|
);
|
||||||
|
threadPoolExecutor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||||
return new BlockingOnFullQueueExecutorServiceDecorator(threadPoolExecutor,
|
return new BlockingOnFullQueueExecutorServiceDecorator(threadPoolExecutor,
|
||||||
maxQueueSize,
|
maxQueueSize,
|
||||||
queueItemTtl,
|
queueItemTtl,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user