How to stop the execution of Executor ThreadPool in java?

前端 未结 2 1061
死守一世寂寞
死守一世寂寞 2020-12-05 13:42

I am working on the Executors in java to concurrently run more threads at a time. I have a set of Runnable Objects and i assign it to the Exceutors.The Executor is working f

2条回答
  •  余生分开走
    2020-12-05 14:21

    The ExecutorService class has 2 methods just for this: shutdown() and shutdownNow().

    After using the shutdown() method, you can call awaitTermination() to block until all of the started tasks have completed. You can even provide a timeout to prevent waiting forever.

    You might want to click on some of these links that I'm providing. They go straight to the docs where you can readup on this stuff yourself.

提交回复
热议问题