I am trying to build an implementation of the ExecutorService
, let\'s call it SequentialPooledExecutor
, with the following properties.
If you want to configure bounded queue, use ThreadPoolExecutor
ThreadPoolExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime,
TimeUnit unit, BlockingQueue workQueue, ThreadFactory threadFactory,
RejectedExecutionHandler handler)
For your use case, use ThreadPoolExecutor
as
ThreadPoolExecutor executor =
ThreadPoolExecutor(1,1,60,TimeUnit.SECONDS,new ArrayBlockingQueue(1000));
Above code caps size of queue is ThreadPoolExecutor
as 1000. If you want to use custom rejected execution handler, you can configure RejectedExeutionHandler
.
Related SE question:
How to properly use Java Executor?