时间:2010-07-26 07:02:28

标签: java multithreading

5 个答案:

答案 0 :(得分:60)

答案 1 :(得分:7)

答案 2 :(得分:5)

由于添加关闭钩子以明确调用shutdown()对我来说不起作用,我在Google的Guava中找到了一个简单的解决方案: com.google.common.util.concurrent.MoreExecutors.getExitingExecutorService

答案 3 :(得分:2)

答案 4 :(得分:0)

我有类似的问题,我用来得到像

这样的错误

o.a.c.loader.WebappClassLoaderBase :: Web应用程序[ROOT]似乎已启动名为[pool-2-thread-1]的线程,但未能将其停止。这很可能造成内存泄漏。堆栈跟踪线程:  sun.misc.Unsafe.park(原生方法)  java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)  java.util.concurrent.locks.AbstractQueuedSynchronizer中$ ConditionObject.await(AbstractQueuedSynchronizer.java:2039)

Bellow code修复了它

private ThreadPoolExecutor executorPool;

@PostConstruct
public void init() {
    log.debug("Initializing ThreadPoolExecutor");
    executorPool = new ThreadPoolExecutor(1, 3, 1, TimeUnit.SECONDS, new ArrayBlockingQueue<Runnable>(1));
}

@PreDestroy
public void destroy() {
    log.debug("Shuting down ThreadPoolExecutor");
    executorPool.shutdown();
}