Rare infinite loop in code, don't want to wait for it to happen again

为君一笑 提交于 2019-12-10 09:52:54

问题


Ok, so I've got a genetic algorithm running in netbeans, and its been running for like 5 hours and seems to have entered an infinite loop. Is there any way that I can attach a debugger to it? or at least get some clue as to where it is in the code? I'd rather not sit around for another 5 hours while I wait for it to happen again.


回答1:


A simple way to get some basic information from your running program is to run jstack on it, it will print stack traces of all threads in your code. Do that several times and you should have a good idea what is wrong.

Use jps to find out the id of your JVM like and then use jstack with that ID:

$ jps
10664 Jps
7141 org.eclipse.equinox.launcher_1.2.0.v20110124-0830.jar
$ jstack 7141

VisualVM provides similar information, if you prefer a GUI application.



来源:https://stackoverflow.com/questions/5753268/rare-infinite-loop-in-code-dont-want-to-wait-for-it-to-happen-again

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!