Any way to quot;rebootquot; the JVM?(任何“重启的方式JVM?)
问题描述
有没有办法重启JVM?如实际上并没有退出,而是关闭并重新加载所有类,然后从顶部运行 main?
Is there any way to reboot the JVM? As in don't actually exit, but close and reload all classes, and run main from the top?
推荐答案
最好的办法可能是在循环中运行 java 解释器,然后退出.例如:
Your best bet is probably to run the java interpreter within a loop, and just exit. For example:
#!/bin/sh
while true
do
java MainClass
done
如果您希望能够完全重启或关闭,您可以测试退出状态:
If you want the ability to reboot or shutdown entirely, you could test the exit status:
#!/bin/sh
STATUS=0
while [ $STATUS -eq 0 ]
do
java MainClass
STATUS=$?
done
在 java 程序中,您可以使用 System.exit(0) 表示您要重新启动",并使用 System.exit(1) 表示您要停止并保持停止状态.
Within the java program, you can use System.exit(0) to indicate that you want to "reboot," and System.exit(1) to indicate that you want to stop and stay stopped.
这篇关于任何“重启"的方式JVM?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:任何“重启"的方式JVM?
基础教程推荐
- 如何对 Java Hashmap 中的值求和 2022-01-01
- Struts2 URL 无法访问 2022-01-01
- 无法复制:“比较方法违反了它的一般约定!" 2022-01-01
- RabbitMQ:消息保持“未确认"; 2022-01-01
- 问题http://apache.org/xml/features/xinclude测试日志4j 2 2022-01-01
- Spring AOP错误无法懒惰地为此建议构建thisJoinPoin 2022-09-13
- 存储 20 位数字的数据类型 2022-01-01
- REST Web 服务返回 415 - 不支持的媒体类型 2022-01-01
- 修改 void 函数的输入参数,然后读取 2022-01-01
- 使用堆栈算法进行括号/括号匹配 2022-01-01
