0

Is there a way to change the value of a java global variable at runtime in websphere application server? I use a properties file in my java application to specify the values of global variables. But I need to change the values of the variables at runtime sometimes. For example, if i have a variable by the name 'fileServerLocation' and the value of it is 'C:\Users\test\Downloads' and if I want to change it to 'C:\Users\test\Desktop', is there a way I can change the value of the variable without having to re-deploy the application on the server?

ancora imparo
  • 82
  • 2
  • 10

3 Answers3

0

You can build a web service or an EJB call that is triggered via an HTTP request and all it does is to change the field value at runtime. You may need to make this "admin request" to require authentication (e.g. username/password) to be executed. Also, you might need to declare this field as volatile in order to be visible across all threads once changed.

Be aware that every ClassLoader has its own value of the static field (the global variable). Usually all EJBs share the same class loader but each war module has its own class loader.

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
0

Don't use "global variables". Create an internal service that provides the values to clients at runtime, and design the service so it has an interface that can accept changes at runtime, via a servlet, message-driven-bean, and/or some other mechanism. Also, have the service allow clients to register callbacks ("listeners") that can be notified when a specific variable value (or any variable value) changes.

Jim Garrison
  • 85,615
  • 20
  • 155
  • 190
  • the client doesn't have to know anything about the variable. the variable is used to represent a folder on the server side. – ancora imparo Aug 23 '13 at 18:34
0

I will not try to understand the details of the global variable but I suppose that the "Global variable" is a per Application global variable.

I will focus on how the dynamic update of in what way a state change should be performed.
I think that the correct way to do this typically management operation is to use the JMX standard. You must expose an MBean with an operation to dynamically update the value in runtime. The update of the value should be "thread safe" using some kind of memory barriers.

The update of the value will be executed using some kind of management tool (JMX client).

Robert Höglund
  • 954
  • 9
  • 12