如何在运行时更改 Java 属性? [英] How to change Java properties at runtime?

查看:28
本文介绍了如何在运行时更改 Java 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:是否有某种方法可以连接"到正在运行的 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?

谢谢!

推荐答案

许多系统属性仅在启动时检查,因此更改它们并不总是有帮助.

Many system properties are only examined on start up so changing them doesn't always help.

我建议您在您的应用程序中添加支持以通过请求执行更改,以便您的应用程序知道它已经发生并相应地处理它.

I suggest you add support within your application to perform the change via a request so your application will know that it has happened and handle it accordingly.

这篇关于如何在运行时更改 Java 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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