How do I know if a Java process has been started in the debugger?

I sometimes use a timer to call System.exit to kill a piece of reset code after a few seconds, which is very useful if it eats a 100% processor and Windows becomes irresponsible because of this. This is very convenient, except when I run it in the debugger. In the debugger, I would like to disable it automatically, otherwise I will forget it, and my debugged process will be killed. Can I find out if a process has been started in the debugger?

Note. I know that I should not use this for something serious. I am not going to.

+3
source share
1 answer

Check here . This checks for JDWP .

:

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

Source: https://habr.com/ru/post/1790932/


All Articles