刚才用jstack解决了一个进程死锁的问题——其实早就解决了,也知道原因,只是一直没找到死锁的位置,不太甘心而已。
流程大致如下:
(0)环境要求,JDK1.6及以上
(1)先找到进程的PID,Windows下,打开进程管理器,按照名字排序,可以找到叫做javaw.exe的进程(java虚拟机进程一律叫做javaw.exe),要找出哪个是你的进程,记住当前进程列表,然后重启你的进程,PID刷新过的那个即是你的进程。
(2)在CMD下运行:jstack pid,jstack会在console上打出一系列信息
(3)分析上述信息
实例:
我这个问题的的jstack信息如下:
C:\Documents and Settings\user>jstack 66522012-06-07 21:32:02Full thread dump Java HotSpot(TM) Client VM (16.3-b01 mixed mode, sharing):"Thread-1" daemon prio=6 tid=0x03010c00 nid=0xcdc waiting for monitor entry [0x0339f000] java.lang.Thread.State: BLOCKED (on object monitor) at org.apache.commons.net.telnet.TelnetInputStream.__read(TelnetInputStream.java:122) - waiting to lock <0x22942280> (a org.apache.commons.net.ftp.FTPClient) at org.apache.commons.net.telnet.TelnetInputStream.run(TelnetInputStream.java:535) at java.lang.Thread.run(Thread.java:619)"Framework Event Dispatcher" daemon prio=6 tid=0x03010400 nid=0x998 in Object.wait() [0x0334f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x228fa800> (a org.eclipse.osgi.framework.eventmgr.EventManager$EventThread) at java.lang.Object.wait(Object.java:485) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.getNextEvent(EventManager.java:400) - locked <0x228fa800> (a org.eclipse.osgi.framework.eventmgr.EventManager$EventThread) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:336)"Start Level Event Dispatcher" daemon prio=6 tid=0x02fcf400 nid=0x2638 in Object.wait() [0x032de000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x2295db48> (a [I) at java.lang.Object.wait(Object.java:485) at org.apache.commons.net.telnet.TelnetInputStream.read(TelnetInputStream.java:339) - locked <0x2295db48> (a [I) at org.apache.commons.net.telnet.TelnetInputStream.read(TelnetInputStream.java:466) at java.io.BufferedInputStream.read1(BufferedInputStream.java:256) at java.io.BufferedInputStream.read(BufferedInputStream.java:317) - locked <0x2295fe18> (a java.io.BufferedInputStream) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:264) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:306) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:158) - locked <0x22961f88> (a java.io.InputStreamReader) at java.io.InputStreamReader.read(InputStreamReader.java:167) at java.io.BufferedReader.fill(BufferedReader.java:136) at java.io.BufferedReader.readLine(BufferedReader.java:299) - locked <0x22961f88> (a java.io.InputStreamReader) at java.io.BufferedReader.readLine(BufferedReader.java:362) at org.apache.commons.net.ftp.FTP.__getReply(FTP.java:264) at org.apache.commons.net.ftp.FTP._connectAction_(FTP.java:335) at org.apache.commons.net.ftp.FTPClient._connectAction_(FTPClient.java:550) at org.apache.commons.net.SocketClient.connect(SocketClient.java:163) at com.mycompany.dc.ftp.client.FTPClientImpl.connect(FTPClientImpl.java:75) - locked <0x22942280> (a org.apache.commons.net.ftp.FTPClient) at com.mycompany.dc.ftp.client.FTPClientFactoryImpl.getClient(FTPClientFactoryImpl.java:35) - locked <0x228f9310> (a java.lang.Object) at ftpclienttest.Activator.start(Activator.java:43) at org.eclipse.osgi.framework.internal.core.BundleContextImpl$1.run(BundleContextImpl.java:711) at java.security.AccessController.doPrivileged(Native Method) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.startActivator(BundleContextImpl.java:702) at org.eclipse.osgi.framework.internal.core.BundleContextImpl.start(BundleContextImpl.java:683) at org.eclipse.osgi.framework.internal.core.BundleHost.startWorker(BundleHost.java:381) at org.eclipse.osgi.framework.internal.core.AbstractBundle.resume(AbstractBundle.java:389) at org.eclipse.osgi.framework.internal.core.Framework.resumeBundle(Framework.java:1131) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:559) at org.eclipse.osgi.framework.internal.core.StartLevelManager.resumeBundles(StartLevelManager.java:544) at org.eclipse.osgi.framework.internal.core.StartLevelManager.incFWSL(StartLevelManager.java:457) at org.eclipse.osgi.framework.internal.core.StartLevelManager.doSetStartLevel(StartLevelManager.java:243) - locked <0x27e68d70> (a java.lang.Object) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:438) at org.eclipse.osgi.framework.internal.core.StartLevelManager.dispatchEvent(StartLevelManager.java:1) at org.eclipse.osgi.framework.eventmgr.EventManager.dispatchEvent(EventManager.java:230) at org.eclipse.osgi.framework.eventmgr.EventManager$EventThread.run(EventManager.java:340)"Framework Active Thread" prio=6 tid=0x02ff1800 nid=0x1fbc in Object.wait() [0x0328f000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x27e65770> (a org.eclipse.osgi.framework.internal.core.Framework) at org.eclipse.osgi.framework.internal.core.Framework.run(Framework.java:1817) - locked <0x27e65770> (a org.eclipse.osgi.framework.internal.core.Framework) at java.lang.Thread.run(Thread.java:619)"OSGi Console" prio=6 tid=0x03005400 nid=0x225c waiting on condition [0x0323f000] java.lang.Thread.State: TIMED_WAITING (sleeping) at java.lang.Thread.sleep(Native Method) at org.eclipse.osgi.framework.internal.core.FrameworkConsole.runConsole(FrameworkConsole.java:125) at org.eclipse.osgi.framework.internal.core.FrameworkConsole.run(FrameworkConsole.java:104) at java.lang.Thread.run(Thread.java:619)"Low Memory Detector" daemon prio=6 tid=0x02c09800 nid=0x1d68 runnable [0x00000000] java.lang.Thread.State: RUNNABLE"CompilerThread0" daemon prio=10 tid=0x02c03000 nid=0x24c4 waiting on condition[0x00000000] java.lang.Thread.State: RUNNABLE"Attach Listener" daemon prio=10 tid=0x02c01800 nid=0x1138 waiting on condition[0x00000000] java.lang.Thread.State: RUNNABLE"Signal Dispatcher" daemon prio=10 tid=0x02c20c00 nid=0x18ac runnable [0x00000000] java.lang.Thread.State: RUNNABLE"Finalizer" daemon prio=8 tid=0x02bc0400 nid=0x11ac in Object.wait() [0x02d8f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x27d5e5c8> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:118) - locked <0x27d5e5c8> (a java.lang.ref.ReferenceQueue$Lock) at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:134) at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)"Reference Handler" daemon prio=10 tid=0x02bbb800 nid=0x9cc in Object.wait() [0x02d3f000] java.lang.Thread.State: WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x27d5e650> (a java.lang.ref.Reference$Lock) at java.lang.Object.wait(Object.java:485) at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116) - locked <0x27d5e650> (a java.lang.ref.Reference$Lock)"main" prio=6 tid=0x008a6c00 nid=0x22ec in Object.wait() [0x0098f000] java.lang.Thread.State: TIMED_WAITING (on object monitor) at java.lang.Object.wait(Native Method) - waiting on <0x22c303c8> (a org.eclipse.core.runtime.internal.adaptor.Semaphore) at org.eclipse.core.runtime.internal.adaptor.Semaphore.acquire(Semaphore.java:55) - locked <0x22c303c8> (a org.eclipse.core.runtime.internal.adaptor.Semaphore) at org.eclipse.core.runtime.adaptor.EclipseStarter.updateSplash(EclipseStarter.java:1251) at org.eclipse.core.runtime.adaptor.EclipseStarter.setStartLevel(EclipseStarter.java:1213) at org.eclipse.core.runtime.adaptor.EclipseStarter.startup(EclipseStarter.java:288) at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:175) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) at java.lang.reflect.Method.invoke(Method.java:597) at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622) at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577) at org.eclipse.equinox.launcher.Main.run(Main.java:1410) at org.eclipse.equinox.launcher.Main.main(Main.java:1386)"VM Thread" prio=10 tid=0x02bba000 nid=0xdb4 runnable"VM Periodic Task Thread" prio=10 tid=0x02c0e400 nid=0x24ac waiting on conditionJNI global references: 677
免责声明:
① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。
② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
软考中级精品资料免费领
- 历年真题答案解析
- 备考技巧名师总结
- 高频考点精准押题
- 资料下载
- 历年真题
193.9 KB下载数265
191.63 KB下载数245
143.91 KB下载数1142
183.71 KB下载数642
644.84 KB下载数2755
相关文章
发现更多好内容猜你喜欢
AI推送时光机通过jstack分析解决进程死锁问题实例代码
后端开发2023-05-30
解决代码中的死锁问题并实现无缓冲通道上的阻塞等待
后端开发2024-04-04
咦!没有更多了?去看看其它编程学习网 内容吧