完成后是否需要收集 swingWorker 线程?
Do I need to collect swingWorker threads when they are done?
我正在使用 GUI 调用 swing 工作线程。
他们完成并执行方法 done()
后,我正在打印 Thread.activeCount()
。我得到一个数字,表明线程仍处于活动状态。
完成后我需要以某种方式收集它们吗?
您不能手动销毁由 SwingWorker
个实例创建的线程。这些线程 运行 在 ThreadPoolExecutor
中未公开。
public final void execute() {
getWorkersExecutorService().execute(this);
}
private static synchronized ExecutorService getWorkersExecutorService()
您必须等待超时。生成的每个线程都有 10 分钟的超时时间。
executorService = new ThreadPoolExecutor(MAX_WORKER_THREADS, MAX_WORKER_THREADS, 10L, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(), threadFactory);
这些线程是守护进程,因此如果它们是您程序中的最后一个线程,程序仍会关闭。
我正在使用 GUI 调用 swing 工作线程。
他们完成并执行方法 done()
后,我正在打印 Thread.activeCount()
。我得到一个数字,表明线程仍处于活动状态。
完成后我需要以某种方式收集它们吗?
您不能手动销毁由 SwingWorker
个实例创建的线程。这些线程 运行 在 ThreadPoolExecutor
中未公开。
public final void execute() {
getWorkersExecutorService().execute(this);
}
private static synchronized ExecutorService getWorkersExecutorService()
您必须等待超时。生成的每个线程都有 10 分钟的超时时间。
executorService = new ThreadPoolExecutor(MAX_WORKER_THREADS, MAX_WORKER_THREADS, 10L, TimeUnit.MINUTES, new LinkedBlockingQueue<Runnable>(), threadFactory);
这些线程是守护进程,因此如果它们是您程序中的最后一个线程,程序仍会关闭。