How to change Java properties at runtime?

前端 未结 5 1539
温柔的废话
温柔的废话 2021-02-07 08:33

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

相关标签:
5条回答
  • 2021-02-07 08:51

    Not a long-term solution, but you could connect a debugger and hot-swap some code that returns the property value you want instead of looking up the property. This requires that you enabled remote debugging when you started JBoss though.

    0 讨论(0)
  • 2021-02-07 08:53

    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).

    0 讨论(0)
  • 2021-02-07 08:53

    As others have already suggested, probably can't change the system property value used by your application. One option might be restarting your application. It seems that Jboss offers JMX enabled stop/start ability for web applications which you can read here though I haven't actually tried it out.

    0 讨论(0)
  • 2021-02-07 08:59

    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.

    0 讨论(0)
  • 2021-02-07 09:03

    you can do it using System.setProperty() method. for example: System.setProperty(key, value);

    0 讨论(0)
提交回复
热议问题