ThreadPool / Executor on both Runnable and Callable - that can exits automatically java8

拈花ヽ惹草 提交于 2019-12-24 02:09:34

问题


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

来源:https://stackoverflow.com/questions/29074604/threadpool-executor-on-both-runnable-and-callable-that-can-exits-automatical

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!