tomcat:在条件线程上等待

罗曼·马赫林

我正在调查tomcat关闭过程的奇怪问题:在runnig shutdown.sh之后,java进程仍然出现(我使用进行了检查ps -ef|grep tomcat),情况有点复杂,因为我对服务器的访问非常有限(没有调试,对于例)

我使用线程转储(通过使用kill -3 <PID>)和堆转储通过使用远程jConsole和热点功能。

在查看线程转储后,我发现了这一点:

"pool-2-thread-1" #74 prio=5 os_prio=0 tid=0x00007f3354359800 nid=0x7b46 waiting on condition [0x00007f333e55d000]
  java.lang.Thread.State: WAITING (parking)
       at sun.misc.Unsafe.park(Native Method)
       - parking to wait for  <0x00000000c378d330> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
       at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
       at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1081)
       at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
       at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
       at java.lang.Thread.run(Thread.java:748)

因此,我对问题的理解如下:CachedThreadpool中使用了一种资源(数据库连接或其他),该资源现已锁定,并防止线程pool-2-thread-1停止。假设此线程不是守护进程-JVM无法正常停止。

有没有办法找出哪个资源被锁定,从何处锁定以及如何避免这种情况?另一个问题是-如何预防这种情况?另一个是:地址0x00007f333e55d000代表什么?

谢谢!

罗曼·马赫林

经过一番苦苦挣扎之后,我发现冻结线程始终具有相同的名称pool-2-thread-1我grep项目的所有源代码,以查找启动任何预定线程池的任何位置:Executors#newScheduledThreadPool经过大量时间后,我在线程池中记录了所有线程的名称。再一台重启服务器和陷阱!

我发现了一个线程池,该线程池仅由一个线程启动,并使用以下代码:

private void shutdownThreadpool(int tries) {
    try {
        boolean terminated;
        LOGGER.debug("Trying to shutdown thread pool in {} tries", tries);
        pool.shutdown();
        do {
            terminated = pool.awaitTermination(WAIT_ON_SHUTDOWN,TimeUnit.MILLISECONDS);
            if (--tries == 0
                    && !terminated) {
                LOGGER.debug("After 10 attempts couldn't shutdown thread pool, force shutdown");
                pool.shutdownNow();
                terminated = pool.awaitTermination(WAIT_ON_SHUTDOWN, TimeUnit.MILLISECONDS);
                if (!terminated) {
                    LOGGER.debug("Cannot stop thread pool even with force");
                    LOGGER.trace("Some of the workers doesn't react to Interruption event properly");
                    terminated = true;
                }
            } else {
                LOGGER.info("After {} attempts doesn't stop", tries);
            }
        } while (!terminated);
        LOGGER.debug("Successfully stop thread pool");
    } catch (final InterruptedException ie) {
        LOGGER.warn("Thread pool shutdown interrupted");
    }
}

之后,问题解决了。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章