开发者

How to find out if a Java process was started in debugger?

I sometimes use a timer to call System.exit in order to kill my throw-away code snippet after few seconds, which is quite useful in case it eats 100% CPU and Windows gets irresponsible because of this. It's quite handy, except in case I start it in debugger. In debugger I'd like to disable it automatically, otherwise I forget it and my debugged process gets killed. Can I find out if a process was started in debugger?

Note: I know I should not use thi开发者_Go百科s for anything serious. I'm not going to.


Check here. This checks for the JDWP.

Basically:

boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().
    getInputArguments().toString().indexOf("-agentlib:jdwp") > 0;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜