Skip to content

Tag: threadpoolexecutor

Why can’t I add tasks to the thread pool the second time in Java?

I create a thread pool to deal with the task, after deal with the task,I find I can not add and start the other task? How to fix it? If I change the executor by executor = new ThreadPoolExecutor(3, 3, 0L, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory(“timeOutThread”)); ,It will run OK.But if the task is canceled because of timeout,do this will

Spring SmartLifecycle start() method not executed

In my spring app I have a thread pool manager that during start() creates some threads and add those to the pool. But while running the start() method is never executed. Any help will be really appreciated. Answer This is for someone facing similar problem. isRunning() is called before start() therefore make sure isRunning() returns false initially then only start()

Executors.newCachedThreadPool() versus Executors.newFixedThreadPool()

newCachedThreadPool() versus newFixedThreadPool() When should I use one or the other? Which strategy is better in terms of resource utilization? Answer I think the docs explain the difference and usage of these two functions pretty well: newFixedThreadPool Creates a thread pool that reuses a fixed number of threads operating off a shared unbounded queue. At any point, at most nThreads