Java 在 sun.misc.Unsafe.park 等待(本地方法)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24241335/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WAITING at sun.misc.Unsafe.park(Native Method)
提问by Konrad
One of my applications hangs under some period of running under load, does anyone know what could cause such output in jstack:
我的一个应用程序在一段时间的负载下运行时挂起,有谁知道什么会导致 jstack 中出现这样的输出:
"scheduler-5" prio=10 tid=0x00007f49481d0000 nid=0x2061 waiting on condition [0x00007f494e8d0000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006ee117310> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:186)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2043)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1085)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:807)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1043)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1103)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
I am seeing this a lot in jstack output when it hangs.
当它挂起时,我在 jstack 输出中看到了很多。
I heavily using Spring @Async & maps, synchronized maps & ehcache.
我大量使用 Spring @Async 和地图、同步地图和 ehcache。
What is interesting this only happens on one of app instances. Two others are running perfectly fine. What else I could investigate to get more details in such case?
有趣的是,这只发生在应用程序实例之一上。另外两个运行得很好。在这种情况下,我还能调查什么以获得更多细节?
I found this post https://stackoverflow.com/questions/23992787/parking-to-wait-for-0xd8cf0070-a-java-util-concurrent-locks-abstractqueuedsbut it is not very useful in my case.
我发现这篇文章https://stackoverflow.com/questions/23992787/parking-to-wait-for-0xd8cf0070-a-java-util-concurrent-locks-abstractqueueds但对我来说它不是很有用。
采纳答案by dsollen
unsafe.park is pretty much the same as thread.wait, except that it's using architecture specific code (thus the reason it's 'unsafe'). unsafe is not made available publicly, but is used within java internal libraries where architecture specific code would offer significant optimization benefits. It's used a lot for thread pooling.
unsafe.park 与 thread.wait 几乎相同,不同之处在于它使用特定于架构的代码(因此它是“不安全的”)。unsafe 未公开提供,但在 Java 内部库中使用,其中体系结构特定代码将提供显着的优化优势。它被大量用于线程池。
So, to answer your question, all the thread is doing is waiting for something, it's not really using any CPU. Considering that your original stack trace shows that you're using a lock I would assume a deadlock is going on in your case.
所以,为了回答你的问题,所有线程正在做的就是等待某事,它并没有真正使用任何 CPU。考虑到您的原始堆栈跟踪显示您正在使用锁,我认为您的情况正在发生死锁。
Yes I know you have almost certainly already solved this issue by now. However, you're one of the top results if someone googles sun.misc.unsafe.park. I figure answering the question may help others trying to understand what this method that seems to be using all their CPU is.
是的,我知道您现在几乎可以肯定已经解决了这个问题。但是,如果有人在 google 上搜索 sun.misc.unsafe.park,您就是最佳搜索结果之一。我想回答这个问题可能会帮助其他人试图理解这种似乎正在使用他们所有 CPU 的方法是什么。
回答by Yoga Gowda
From the stack trace it's clear that, the ThreadPoolExecutor > Worker thread started and it's waiting for the task to be available on the BlockingQueue(DelayedWorkQueue) to pick the task and execute.So this thread will be in WAIT status only as long as get a SIGNAL from the publisher thread.
从堆栈跟踪可以清楚地看出,ThreadPoolExecutor > Worker 线程已启动,它正在等待 BlockingQueue(DelayedWorkQueue) 上的任务可用以选择任务并执行。来自发布者线程的信号。
回答by boly38
I had a similar issue, and following previous answers (thanks!), I was able to search and find how to handle correctly the ThreadPoolExecutor terminaison.
我有一个类似的问题,按照以前的答案(谢谢!),我能够搜索并找到如何正确处理 ThreadPoolExecutor 终止。
In my case, that just fix my progressive increase of similar blocked threads:
就我而言,这只是修复了我逐渐增加的类似阻塞线程:
- I've used
ExecutorService::awaitTermination(x, TimeUnit)
andExecutorService::shutdownNow()
(if necessary) in my finally clause. For information, I've used the following commands to detect thread count & list locked threads:
ps -u javaAppuser -L|wc -l
jcmd `ps -C java -o pid=` Thread.print >> threadPrintDayA.log
jcmd `ps -C java -o pid=` Thread.print >> threadPrintDayAPlusOne.log
cat threadPrint*.log |grep "pool-"|wc -l
- 我在我的 finally 子句中使用了
ExecutorService::awaitTermination(x, TimeUnit)
andExecutorService::shutdownNow()
(如有必要)。 有关信息,我使用以下命令来检测线程计数并列出锁定的线程:
ps -u javaAppuser -L|wc -l
jcmd `ps -C java -o pid=` Thread.print >> threadPrintDayA.log
jcmd `ps -C java -o pid=` Thread.print >> threadPrintDayAPlusOne.log
cat threadPrint*.log |grep "pool-"|wc -l