重启自己 - 我可以从头开始重新初始化一切吗? [英] Restart myself - can I reinitialize everything from scratch?

查看:138
本文介绍了重启自己 - 我可以从头开始重新初始化一切吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的事情:

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再次调用静态初始值设定项,然后主(...)

I want to reinitialize the JVM calling the static initializer again, and then main(...)!

能否完成?

推荐答案

您可以使用自定义类加载器启动应用程序,这将允许您加载和卸载静态变量。

You can start your application using a custom class loader, this will allow you to load and unload your static variables.

然而,基本上它是一个非常糟糕的设计需要去做这个。我喜欢让田野最终,但如果你想改变它们,你不应该让它们成为最终的。

However, basically its a very bad design to need to do this. I like making fields final, but you shouldn't make them final if you want to change them.

这篇关于重启自己 - 我可以从头开始重新初始化一切吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆