shutdownNow() ExecutorService method

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

The Sun documentation says that shutdownNow() is only a "best-effort"
attempt to end all processing tasks. Is it reasonable to assume that
the Java implementation will attempt to end the tasks with either
Thread.interrupt() (and code appropriately for that possibility) or
some other transparent method with a high probability of success? I
am using the 1.5 Windows implementation from Sun, so I would gather
that in all likelihood coding for Thread.interrupt() will be
sufficient, but I find the Sun documentation to be uncomforting.
 
O

Oliver Wong

Christopher Benson-Manica said:
The Sun documentation says that shutdownNow() is only a "best-effort"
attempt to end all processing tasks. Is it reasonable to assume that
the Java implementation will attempt to end the tasks with either
Thread.interrupt() (and code appropriately for that possibility) or
some other transparent method with a high probability of success? I
am using the 1.5 Windows implementation from Sun, so I would gather
that in all likelihood coding for Thread.interrupt() will be
sufficient, but I find the Sun documentation to be uncomforting.

The JavaDocs say that "typical implementations" will cancel via
Thread.interrupt(). This indicates that it is not required by the contract
of this method that Thread.interrupt() actually be the mechanism used for
cancelling tasks.

In other words, I'd probably avoid using this shutdownNow() method if I
were you.

Perhaps if you were using a specific implementation (e.g.
ThreadPoolExecutor), you could find a firmer, publicly documented contract.

- Oliver
 
C

Christopher Benson-Manica

Oliver Wong said:
Perhaps if you were using a specific implementation (e.g.
ThreadPoolExecutor), you could find a firmer, publicly documented contract.

I will take a look at using a ThreadPoolExecutor for this task. Thank
you for your helpful reply.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top