简体   繁体   English

tomcat:在条件线程上等待

[英]tomcat: Waiting on condition thread

I'm investigating the strange issue with tomcat shutdown process: after runnig shutdown.sh the java process still appears(I check it by using ps -ef|grep tomcat ) The situation is a bit complicated, because I have very limitted access to the server(no debug, for example) 我正在调查tomcat关闭过程的奇怪问题:在runnig shutdown.sh之后,java进程仍然出现(我使用ps -ef|grep tomcat对其进行了检查)这种情况有点复杂,因为我对服务器(例如,没有调试)

I took thread dump(by using kill -3 <PID> ) and heap dump by using remote jConsole and Hotspot features. 我进行了线程转储(通过使用kill -3 <PID> ),并通过使用远程jConsole和Hotspot功能进行了堆转储。

After looking into thread dump I found this: 查看线程转储后,我发现了这一点:

"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)

So, my understanding of the problem is follows: There is a resource(DB connection or something else) which is used in CachedThreadpool, and this resource is now locked, and prevent to thread pool-2-thread-1 to stop. 因此,我对问题的理解如下:在CachedThreadpool中使用了一种资源(数据库连接或其他),该资源现已锁定,并防止线程pool-2-thread-1停止。 Assuming that this thread isn't deamon - JVM cannot gracefully stop. 假设此线程不是守护进程-JVM无法正常停止。

Is there a way to find out which resource is locked, from where is it locked and how to avoid that? 有没有办法找出哪个资源被锁定,从何处锁定以及如何避免这种情况? Another question is - how to prevent this situation? 另一个问题是-如何预防这种情况? Another this is: what the adress 0x00007f333e55d000 is for? 另一个是:地址0x00007f333e55d000代表什么?

Thanks! 谢谢!

After a wail of struggling I found out, that the freezing thread always have the same name pool-2-thread-1 . 经过一番努力之后,我发现冻结线程始终具有相同的名称pool-2-thread-1 I grep all the sources of the project to find any places where any scheduled thread pool is started: Executors#newScheduledThreadPool . 我使用grep项目的所有源代码来查找启动任何预定线程池的任何位置: Executors#newScheduledThreadPool After a huge amount of time I logged all that places, with thread name in thread pool. 经过大量时间后,我在线程池中记录了所有线程名称。 One more restart server and gotcha! 再一台重启服务器和陷阱!

I found out one thread pool, that is started with only one thread and used following code: 我发现了一个线程池,该线程池仅由一个线程启动,并使用以下代码:

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");
    }
}

After that the issue was solved. 之后,问题解决了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM