[concurrency-interest] Shutting down ExecutorService

Alexander Malyuk amalyuk at gmail.com
Fri Apr 17 15:26:18 EDT 2009


http://gee.cs.oswego.edu/dl/cpj/cancel.html
On Fri, Apr 17, 2009 at 1:03 PM, Thomas Barnett <barnett.thomas at gmail.com>wrote:

> I am trying to wrap my head around concurrency package. There is an
> example of use of ExecutorService in LifecycleWebServer listing in the
> book JCIP by Goetz et al [1]. It goes:
>
> ...
> while(!exec.isShutDown()) {
>  try {
>    final Socket conn = socket.accept();
> ...
>
> and has a stop() method that shuts down executor service. 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.
>
> 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?
>
> Regards
> Thomas
>
> [1] http://jcip.net/
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
> http://cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20090417/ed3f60b2/attachment-0001.html>


More information about the Concurrency-interest mailing list