问题
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:
- JPDA?
- Observer & Observable?
- Property change listener?
- JMX?
Any suggestions? Thanks in advance.
回答1:
You can replace the system Properties with your own custom subclass.
MyProperties newProps = new MyProperties(System.getProperties());
System.setProperties(newProps);
Then, just write a subclass of Properties which hooks the relevant methods.
回答2:
If you primarily want to find the issue, I would look at using the SecurityManager for this. It has a couple methods available checkPropertiesAccess() and checkPropertyAccess() which look like they will help you to find the issue, but not necessarily be able to 'notify you when a system property has changed.'
来源:https://stackoverflow.com/questions/10710450/how-to-detect-if-a-java-system-property-has-changed