Java API to turn on debugging in a running JVM

こ雲淡風輕ζ 提交于 2019-12-10 21:57:38

问题


Is there a programmatic way to turn on debugging in a running JVM instance? I am looking for an API that would make a running JVM, a debug server. The API would do the equivalent of

-Xdebug -Xrunjdwp:transport=dt_socket,address=<host:port>,server=y,suspend=n. 

回答1:


This is not possible. The JVM has to know from the beginning that it is in debug mode. It runs a bit slower then but provides external processes with debug information and breakpoints which is not possible when the JVM already has been startet.




回答2:


You can attach to any running JVM using Visual VM. Be sure to download version 1.3.2 and install all the plugins.




回答3:


The debug port that the questioner refers to is for source code debugging, such as with an Eclipse debugger. The port for VisualVM is the JMX port, which takes a different set of JVM options. There are exceptions though: Mission Control for JRockit uses the jdwp port rather than the JMX port.

And yes, you can dynamically load the JMX debugger in code. Its complicated but OSGI can load this dynamically I believe. For example, here is a reference to Jetty project doing this.



来源:https://stackoverflow.com/questions/6934571/java-api-to-turn-on-debugging-in-a-running-jvm

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