Comments (7)
yeah. the problem is that any such hook will be unthreadsafe, and/or force synchronization where we currently have none, so it's tricky to figure out how to go about it. I think there might already be a super hacky private hook used in the tests for the lib itself but it has problems.
from config.
So are you saying that "yes this is useful but hard to implement" or "is't not worth implementing"? :-)
from config.
It's definitely useful, but there might be a tradeoff where it either slows down production code with a global lock or is unthreadsafe/dangerous, so it isn't a no-brainer definitely-good thing to add. I'm not sure exactly how bad the tradeoff is without digging in a bit to try to see how it might work.
Hmm. Looking at the code, getting the singleton is already synchronized (see LoaderCache.getOrElseUpdate in ConfigImpl.java). We drop the cache if the class loader changes. We could also drop the cache if the system properties config has been changed.
The method to reload the system properties config already exists in impl/ConfigImpl.java (reloadSystemPropertiesConfig) but it isn't threadsafe.
If SystemPropertiesHolder.systemProperties were volatile then I guess the worst case is that you get the old system properties, which may be "threadsafe enough" for this case.
So maybe it's just 1) in LoaderCache.getOrElseUpdate check for SystemPropertiesHolder.systemProperties changed in addition to class loader changed 2) put volatile on SystemPropertiesHolder.systemProperties 3) make a public wrapper for reloadSystemPropertiesConfig()
But there may be complications once we get into it.
from config.
I also need this feature
from config.
As long as in the end the returned Config() is immutable (and not refreshable, whatever that would mean), I think we’re fine. Creating new Config()s should be a rare operation, and if it needs synchronization that will not kill it. It should be lockless, though, because you wouldn’t think that reading system properties could block. As @havocp said, having one reader (who did not explicitly request a refresh) read “old” data is fine; so I think it would just need to be a volatile field somewhere and “last refresher wins” semantics.
from config.
I agree with @rkuhn, production code should be reloading config very, very infrequently. My own use-case is specifically motivated by unit tests only.
As for thread safety, System properties are inherently thread unsafe. You could add internal synchronization to guard against multiple threads reloading the config concurrently but with appropriate caveats in documentation, I think most callers should be OK without it.
from config.
In 0.6.0 just published (may take a bit to sync to maven)
from config.
Related Issues (20)
- Find a StackOverflowError in config
- Find a StackOverflowError in config
- Find a StackOverflowError in config HOT 1
- underscore characters HOT 2
- Problems with com.typesafe/config and maven-dependency-plugin
- introduce method accepting a list of Objects to add a value
- Should this project be explicitly considered as deprecated/not supported? HOT 29
- Community fork? HOT 7
- Resolving Variable Substitutions Between Multiple Config HOT 1
- Something error when use com.typesafe.config API convert conf file to scala bean class
- withFallBack is not adding value if not present
- how to load the config with substitution details HOT 3
- Add info about which signing keys will be used for published artifacts.
- Cannot provide environment variables programmatically
- Rendering partially resolved appended array results in invalid configuration HOT 1
- Inconsistent behavior with Overflow/Underflow and Exceptions
- Regression in environment variable reading behavior HOT 2
- Add a module info HOT 6
- Question about `ConfigFactory.systemProperties()` on windows HOT 1
- When rendering unresolved ConfigConcatenation, whitespaces are erroneously included
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from config.