我有这样的事情:
public static final String path;
static {
path = loadProperties("config.conf").getProperty("path");
}
public static void main(String... args) {
// ... do stuff (starting threads that reads the final path variable)
// someone want's to update the path (in the config.conf file)
restart(); // ???
}
我想重新初始化 JVM,再次调用静态初始化程序,然后main(...)
!
能做到吗?
您可以使用自定义类加载器启动应用程序,这将允许您加载和卸载静态变量。
然而,基本上这是一个非常糟糕的设计,需要这样做。我喜欢将字段定为最终字段,但如果您想更改它们,则不应将它们定为最终字段。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)