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 t开发者_如何学运维o 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?
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)
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.
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
精彩评论