开发者

Can a Java.exe JVM restart itself somehow?

开发者 https://www.devze.com 2022-12-11 14:53 出处:网络
Can a Java.exe JVM restart itself somehow?If you have a Java program running in a DOS shell (NOT as a service), what is the cleanest, most efficient way for it t开发者_JS百科o shut down, close the she

Can a Java.exe JVM restart itself somehow? If you have a Java program running in a DOS shell (NOT as a service), what is the cleanest, most efficient way for it t开发者_JS百科o shut down, close the shell, and restart itself with a different Windows process id and re-open in a different shell with a reloaded classpath?

I expect it's not possible but I thought I should ask and learn from other people by asking.

NOTE: If anyone knows how Eclipse IDE is able to restart itself so cleanly, that is the method I am wanting to use.


The Java Service Wrapper can help here. You can run your Java process under it but not necessarily as a service. You can define restart characteristics, such that if it exits, the Java program is restarted (either by System.exit() or calling WrapperManager.restart()).


The cleanest and simplest way to do that would be to run the program from a DOS batch file (or CMD script, if you prefer). Build a loop into your DOS batch file. You put a :label near the beginning and a GOTO label below your Java process and off it goes. If need be, you can break out of the loop using Ctrl-C.


Create a separate executable that takes a process ID and a command as command line argument, waits for the specified process to close and then runs the specified command. Launch that program, then exit the current instance.

You can either embed that program in your primary program and copy it to a temporary directory to execute it, or include it side-by-side with your program.

0

精彩评论

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

关注公众号