16

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?

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?

Thank you!

Bruno Teixeira
  • 3,099
  • 3
  • 16
  • 8
  • 1
    Have you considered using java.util.prefs.Preferences? http://download.oracle.com/javase/1.4.2/docs/guide/lang/preferences.html – Koekiebox Dec 17 '10 at 11:10
  • 4
    A good example of why things should be properly tested before they are deployed. – OrangeDog Dec 17 '10 at 11:35

5 Answers5

5

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

Michał Niklas
  • 53,067
  • 18
  • 70
  • 114
4

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.

Peter Lawrey
  • 525,659
  • 79
  • 751
  • 1,130
  • well if I manage to change the prop and then restart the app through JBoss's Admin Console, the application should read it again, right? – Bruno Teixeira Dec 17 '10 at 11:41
  • 1
    @Bruno Teixeira, if you change the property from where ever JBoss get it from and restart it will pick it up. If you change it at runtime, the properties are not saved. I suggest you just try changing the property at run-time see if it does what you expect. It all depends on what the property is and which library uses it. – Peter Lawrey Dec 17 '10 at 12:08
1

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.

Sanjay T. Sharma
  • 22,857
  • 4
  • 59
  • 71
1

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.

OrangeDog
  • 36,653
  • 12
  • 122
  • 207
0

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

GuruKulki
  • 25,776
  • 50
  • 140
  • 201