如何在运行时更改Java属性? [英] How to change Java properties at runtime?
问题描述
问题:
是否有某种方法可以连接到正在运行的JVM并更改系统属性(由-Dproperty = value给出)而无需停止JVM并且没有编写方法来执行此操作?
The question: Is there some way to "connect" to a running JVM and change system properties (given by -Dproperty=value) without stopping the JVM and without having programmed a way of doing it?
现在,上下文:
我在远程机器上运行JBoss服务器,它托管我的应用程序,还有其他应用程序。其他应用程序可能无法停止。使用与我的应用程序相关的特定-D属性调用服务器。在服务器启动时为此属性分配了错误的值。我需要改变那个属性。最简单的方法是重启JBoss,但这会导致所有应用程序停机一段时间。有没有办法在不停止任何应用程序的情况下更改该属性,而不是我自己的?
Now, the context: I have a JBoss server running on a remote machine, which is hosting my application, but also other applications. Those other apps may not be stopped. The server is invoked with a specific -D property that is relevant to my application only. This property was assigned the wrong value at server startup. I need to change that property. The easiest way would be to restart JBoss, but that would cause all apps to go down for some time. Is there a way of changing that property without stopping any applications but my own?
谢谢!
推荐答案
在我的一个代码中找到的示例:
Example found in one of my code:
System.setProperty("javax.net.ssl.trustStore", keystore_file);
您可以运行它以响应重新配置查询(添加重新配置( )
到您的服务器代码。)
You can run it in response for "reconfigure" query (add reconfigure()
to your server code).
这篇关于如何在运行时更改Java属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!