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.
Best practice when reinitialize an Executor
-
30-11-2021 - |
Question
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.
La solution
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow