Google Guice - Update singleton dynamically at runtime

21 Views Asked by At

We have a guice-based service that injects a module when the host is newly brought up. This module creates a new endpoint client (as a singleton) that is used by all the threads for that service (i.e. the state is maintained). I now need to dynamically update this endpoint client (which is in the form of a singleton) at runtime. Note that I need to do this in a thread safe way so that the threads already running are not affected.

There are two questions that I currently have with respect to the above:

  • Is it okay to update a singleton (since singletons are usually expected to be immutable)?
  • If yes, then how do I go about doing the same? I'm fine with either updating the singleton directly, or replacing it with another singleton that is created by injecting a module (both will be done at runtime and in a thread safe way).
0

There are 0 best solutions below