Closed GoogleCodeExporter closed 9 years ago
Seems reasonable, although it might make more sense to group shutdown-related
methods in a Shutdown or ShutdownHooks class.
Original comment by kevin...@gmail.com
on 1 Sep 2011 at 5:29
Original comment by fry@google.com
on 10 Dec 2011 at 4:15
I'm not sure what's being suggested here, or what the signature of this method
would be...?
Original comment by wasserman.louis
on 25 Apr 2012 at 6:34
wasserman.louis: I'd suggest stopServiceOnJvmShutdown() or
stopServiceOnJvmShutdown(boolean)
Original comment by d...@urbanairship.com
on 25 Apr 2012 at 6:49
I was originally thinking along the lines of a
Services.addShutdownHook(Service) call which at a high level might look
something like:
public static void addShutdownHook(final Service service) {
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
service.stopAndWait();
}
});
}
Though it would probably be cleaner if there was an inner class with a thread
name. There probably also only needs to be one thread for all services which
are being stopped on shutdown (which would also be more convenient for
supporting a removeShutdownHook(Service) call).
The example I was referencing is at the bottom of this page:
http://code.google.com/p/google-guice/wiki/ModulesShouldBeFastAndSideEffectFree
Original comment by jer...@gustie.com
on 26 Apr 2012 at 2:57
Scratch my previous comment about a single thread for all the services: it
occurred to me that services can be stopped prior to shutdown in which case a
strong reference should be avoided so the terminated service can be reclaimed.
It also seems like there should not really be a need for removing the shutdown
hook (the service itself could always be stopped ahead of time).
It looks like MoreExecutors already has some shutdown hook support for
ExecutorService instances, I'm not sure if that could be combined like kevin
suggested or if a general Services utility class makes more sense. A third
option could an AbstractExitingService.
Original comment by jer...@gustie.com
on 30 May 2012 at 12:45
Original comment by kevinb@google.com
on 30 May 2012 at 7:43
I recently updated my own implementation of this functionality to use a service
listener: `starting` registers the hook (which is just a thread that calls
`stopAndWait`), `terminated` and `failed` both remove it (and discards the
reference to the thread). Since past state changes aren't replayed to
listeners, I also make sure the hook is registered if the service is already up.
Original comment by jer...@gustie.com
on 31 Jan 2013 at 12:31
This issue has been migrated to GitHub.
It can be found at https://github.com/google/guava/issues/<id>
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:15
Original comment by cgdecker@google.com
on 1 Nov 2014 at 4:18
Original comment by cgdecker@google.com
on 3 Nov 2014 at 9:09
Original issue reported on code.google.com by
jer...@gustie.com
on 17 Aug 2011 at 2:41