如何检测Java System属性是否已更改? [英] How to detect if a Java System property has changed?

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

问题描述

我想知道何时更改系统属性.我在应用程序服务器中有一个应用程序,它某种程度上正在更改系统属性(我认为是System.setProperty()).我看了一下,发现了不同的方法:

I would like to know when a System property is changed. I have an application, in an application server, that somehow is changing a system property (System.setProperty() I think). I was taking a look and I have found different approaches:

  1. JPDA?
  2. 观察者&可以观察到吗?
  3. 属性更改侦听器?
  4. JMX?
  1. JPDA?
  2. Observer & Observable?
  3. Property change listener?
  4. JMX?

有什么建议吗?预先感谢.

Any suggestions? Thanks in advance.

推荐答案

您可以使用自己的自定义子类替换系统属性.

You can replace the system Properties with your own custom subclass.

MyProperties newProps = new MyProperties(System.getProperties());
System.setProperties(newProps);

然后,只需编写一个Properties的子类,该子类会钩住相关方法.

Then, just write a subclass of Properties which hooks the relevant methods.

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

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