[concurrency-interest] Shutting down ExecutorService
davidcholmes at aapt.net.au
Sat Apr 18 00:24:06 EDT 2009
Thomas Barnett writes:
> ... The problem
> is, unless there is a client connection, socket.accept blocks and the
> condition is never checked so LifecycleWebServer never terminates even
> after calling stop(). Trying to use interruption for cancellation as
> in listing 7.5 of the same book does not work either when the blocking
> method is not interruptible. I just want to make sure that I am not
> misunderstanding something here.
The entire contents of Chapter 7 is about cancellation and shutdown, and
covers interruption and its limitations, and what you can do for some
non-interruptible methods ( see 7.1.6) ...
> A workaround I could think of was to set timeout on server socket and
> consume the SocketTimeoutException which seem to work but would that
> be a correct way to do this?
... but for some strange reason in the list in 7.1.6 we forgot to include
setting the socket timeout for things like socket.accept(). Don't know how
we overlooked that given it's been part of an example we used for years
prior to JCiP being written.
Yes setting the socket timeout is exactly how you would deal with this.
More information about the Concurrency-interest