ThreadPool / Executor on both Runnable and Callabl

2019-07-18 04:19发布

问题:

I am trying to use a ThreadPoolExecutor/ExecutorService in my application - it is a static global object. I use: Executors.newScheduledThreadPool(corePoolSize) - but I am having problems with shutting down the executorService.

If I don't call shutdown() + awaitTermination() - then my application won't finish -even if all threads are completed.

My application has threads being created by other threads - so I can't put a shutdown() anywhere in the code without blocking further threads to be run.

Is there a way to let java shutdown() the executor service when all threads are completed.

Thanks

-- Also this question is not a duplicate - the daemon fix makes my application exits before all threads are completed (See comment) - What will be a fix for this? Thanks