0

I am running multiple APIs which load default properties from a text file.
If however, 1 API changes a property value, i want that all APIs then be able to read the new value.
I tried using System.setProperty("prop_name",) but this does not make changes to to other APIs.
I do not want to modify the original text file. Also want to avoid an increased overhead of writing a new properties file and making all APIs load this file (There are a lot of APIs and a lot of properties and dont want this to happen for every single property change).

How do I do this?

2
  • 4
    I think you need to look into the meaning of the word "API" Apr 20, 2011 at 22:13
  • How do the libraries actually load the properties? Does each library read from the file directly, or is the file read in a single place and the libraries receive a Properties object? Apr 20, 2011 at 22:14

2 Answers 2

1

You need to change the libraries to take a shared Properties object or use System.getProperties(). If each library does Properties.load(...) directly by opening a file, then your choice are limited:

  • modify the properties file
  • use a custom classloader to modify the bytecode of the libraries as they are loaded to intercept the call to Properties.load(...)
  • modify the Properties class in the JDK source (included in this list for completeness only)
1
  • . I do not want to change the original properties file. This is because all the programs should start with the default values. Only during runtime if a value changes, then the new value should be used.
    – Andy
    Apr 20, 2011 at 22:39
0
  1. You could spawn a reaper thread for each JVM that polls the files in a directory looking for changes and applying them as they are applicable to that JVM.

  2. You could connect all of your Applications to a server application using the socket API. The server could administer the properties and the clients could poll periodically for changes.

Basically what you are doing is facilitating inter process communication. So any of the standard means for doing that(files, pipes, sockets, web services, etc.) should allow you to synchronize properties across your applications. The more granular(in terms of dispatching individual changes as opposed to wipe and reload) you want to be the more complex your solution

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.