I have a Swing application, which uses a ThreadPoolExecutor to perform multiple tasks. At one point, I want to reinitialize everything. I am using executor.purge(); and executor.getQueue().clear(); Is this enough? Are there any better ways / practices to perform this? Thanks in advance.

有帮助吗?

解决方案

IMHO you should just shutdownNow() the pool and create a new one. If not done too often, it's much simpler. It will also behave safely with already running jobs. Moreover the semantics of purge() are a bit fuzzy.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top