What are the possible reason for a java.util.concurrent.RejectedExecutionException in a SingleThreadExecutor

前端 未结 4 520
执笔经年
执笔经年 2020-12-08 13:13

I create the following executor in a singleton:

   final private ExecutorService executor = Executors.newSingleThreadExecutor(new ThreadFactory() {
                 


        
4条回答
  •  时光说笑
    2020-12-08 13:22

    Maybe you should use a thread pool instead of using a single executor.

        executor = new java.util.concurrent.ThreadPoolExecutor(30, 30, 60, TimeUnit.SECONDS, new LinkedBlockingQueue(), new ThreadFactory() {
            final AtomicInteger threadNumber = new AtomicInteger( 1 );
            @Override
            public Thread newThread(Runnable r) {
                return new Thread(r, "Thread No : " + threadNumber.getAndIncrement());
            }
        });
    

提交回复
热议问题