java.lang.Thread.State中90%线程分析:WAITING(停车)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40080004/
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
Analysis of 90% threads in java.lang.Thread.State: WAITING (parking)
提问by Patan
Thread count in my tomcat application server is growingevery day.
我的 tomcat 应用服务器中的线程数每天都在增长。
When I have taken thread dump for analysis.
当我进行线程转储进行分析时。
I found that out of 430 threads 307 threads are with this status.
我发现 430 个线程中有 307 个线程处于此状态。
Sample stacktrace
示例堆栈跟踪
"pool-283-thread-1" #2308674 prio=5 os_prio=0 tid=0x000000000a916800 nid=0x1101 waiting on condition [0x00002aec87f17000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006d9929ec0> (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.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
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:745)
Locked ownable synchronizers:
- None
"pool-282-thread-1" #2307106 prio=5 os_prio=0 tid=0x000000000a4fb000 nid=0x78e3 waiting on condition [0x00002aec87e16000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x00000006d8ca7bf8> (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.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
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:745)
Locked ownable synchronizers:
- None
Environment
环境
JDK: jdk1.8.0_60
OS: Linux
Tomcat: tomcat-7.0.65
Not sure if this is causing the issue.
不确定这是否导致了问题。
Appreciate any help on this.
感谢您对此的任何帮助。
回答by Antoniossss
This is typical resource leak. You are using some sort of ExecutorService
somewhere in your application and you are not closing that pool after work is done causing threads to await forever.
这是典型的资源泄漏。您正在ExecutorService
应用程序中的某个地方使用某种类型的东西,并且在工作完成后您没有关闭该池,从而导致线程永远等待。
You should call ExecutorService#shutdown()
to close pool and release/terminate its threads after work is done.
您应该ExecutorService#shutdown()
在工作完成后调用关闭池并释放/终止其线程。
Threads names like pool-282-thread-1
pool-283-thread-1
suggests that you are most probably using single thread pool executor (because pool no. is large and thread no. is only 1). The idea behind ExecutorService
is to reuse threads that are idle to do some more work. So insteed of createing new ExecutorService
each time you need to do some background work, you should rather share single instance and use it in your application.
线程名称 likepool-282-thread-1
pool-283-thread-1
表明您很可能正在使用单线程池执行程序(因为池号很大,而线程号仅为 1)。背后的想法ExecutorService
是重用空闲的线程来做更多的工作。因此,不要在ExecutorService
每次需要做一些后台工作时都创建新的,您应该共享单个实例并在您的应用程序中使用它。
回答by Krishnan Manikandan
This issue happened in our application. We fixed it by using single ExecutorServiceinstead of creating ExecutorServiceeach time.
这个问题发生在我们的应用程序中。我们通过使用单个 ExecutorService而不是每次都创建ExecutorService来修复它。