Reputation: 79
I am using a GUI to call swing worker threads.
After they finish and excute the method done()
, I am printing Thread.activeCount()
. I get a number which indicates the threads are still active.
Do I need to collect them somehow when they are done?
Upvotes: 2
Views: 275
Reputation: 15146
You cannot manually destroy the threads created by SwingWorker
instances. These threads run in a ThreadPoolExecutor
which is not exposed.
public final void execute() {
getWorkersExecutorService().execute(this);
}
private static synchronized ExecutorService getWorkersExecutorService()
You'll have to wait for the timeout. Each thread that's generated has a time-out of 10 minutes.
executorService = new ThreadPoolExecutor(MAX_WORKER_THREADS, MAX_WORKER_THREADS, 10L, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(), threadFactory);
These threads are daemon, so the program will still shutdown if they're the last threads in your program.
Upvotes: 2