Skip to content
Advertisement

best ways to dynamically load config in java?

i am designing a web service in java where i need to do a sort of AB testing with requests in java.

Basically I’m looking for ways to easily configure parameters which will be dynamically loaded by a request handler to determine the code path based on config values.

for example, let’s say i need to get some data either from an external web service or from local DB. i want to have a way to configure parameters(criteria in this context) so that it would determine whether to go fetch data from external web service or from local DB.

if i go with a key-value pair config system above example might produce something like this.

JavaScript

which would mean that i would be fetching data from local DB for 30% of requests from US users whose user-agent is firefox. and i would like this config system to be dynamic so that server does not need to be restarted.

sorry about very high level description but any insights/leads would be appreciated. if this is a topic that is beaten to death in the past, please kindly let me know the links.

Advertisement

Answer

I’ve used this in the past. It is the most common way in java to achieve what you are asking using java.util.Properties:

JavaScript

}

Then in your main class you can do:

JavaScript

Then you can check the values of those variables in every other class like:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement