Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Is it possible to change/modify/adding VM parameters after the JVM is already loaded (running)? If so, how can I do it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
125 views
Welcome To Ask or Share your Answers For Others

1 Answer

For properties you'd set via the -D flag on the command line, you want System.setProperty. For example:

System.setProperty("propname", "hello world");

// ... later ...
String value = System.getProperty("propname");

Update:

You can't enable debugging dynamically, but you can enable debugging at startup but attach a debugger later. With the following, you can listen on port 12345 and start your program running right away (via suspend=n). Then you can attach a debugger if/when you need to, detach the debugger, attach again later, etc.

-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=12345

Of course, this hurts performance even when the debugger isn't attached, so it only works well in dev/test code, not production. For that, you want logging, e.g. log4j.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...