开发者

How to make changes to properties persistent in java

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)


  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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜