Git Product home page Git Product logo

Comments (7)

havocp avatar havocp commented on August 18, 2024

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.

diwakergupta avatar diwakergupta commented on August 18, 2024

So are you saying that "yes this is useful but hard to implement" or "is't not worth implementing"? :-)

from config.

havocp avatar havocp commented on August 18, 2024

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.

 avatar commented on August 18, 2024

I also need this feature

from config.

rkuhn avatar rkuhn commented on August 18, 2024

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.

diwakergupta avatar diwakergupta commented on August 18, 2024

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.

havocp avatar havocp commented on August 18, 2024

In 0.6.0 just published (may take a bit to sync to maven)

from config.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.