当tomcat重新加载时,我得到了
WARNING: The web application [myapp] appears to have started a thread named [UrlChecker-2] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
sun.misc.Unsafe.park(Native Method)
java.util.concurrent.locks.LockSupport.parkNanos(Unknown Source)
java.util.concurrent.SynchronousQueue$TransferStack.awaitFulfill(Unknown Source)
java.util.concurrent.SynchronousQueue$TransferStack.transfer(Unknown Source)
java.util.concurrent.SynchronousQueue.poll(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.getTask(Unknown Source)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
java.lang.Thread.run(Unknown Source)
我能想到的唯一解决方法是:
Set<Thread> threads = Thread.getAllStackTraces().keySet();
for (Thread t : threads) {
System.out.println("Thread: " + t.getName() + " " + t.getClass().getName());
String name = t.getName();
if (name.contains("UrlChecker")) {
System.out.println("Interrupting thread " + name + " " + t.getState());
long start = System.currentTimeMillis();
t.interrupt();
t.join();
long end = System.currentTimeMillis();
long diff = (end - start) / 1000;
System.out.println("Time diff " + diff);
}
}
这远非理想,不仅我正在使用魔法字符串'UrlChecker'进行搜索,我也在打断TIMED_WAITING线程,这迫使我等待60秒再关闭逻辑恢复。
线程从私有静态Executor启动。 UrlChecker课程可以在这里查看:
我已经与Selenium家伙提出了这个问题:https://github.com/SeleniumHQ/selenium/issues/2716