Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #30356 > unrolled thread
| Started by | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| First post | 2014-11-15 03:53 -0800 |
| Last post | 2014-11-15 06:11 -0600 |
| Articles | 4 — 3 participants |
Back to article view | Back to comp.lang.java.programmer
language lawyer request for ExecutorService Roedy Green <see_website@mindprod.com.invalid> - 2014-11-15 03:53 -0800
Re: language lawyer request for ExecutorService Roedy Green <see_website@mindprod.com.invalid> - 2014-11-15 04:04 -0800
Re: language lawyer request for ExecutorService Sebastian <news@seyweiler.dyndns.org> - 2014-11-25 22:59 +0100
Re: language lawyer request for ExecutorService Leif Roar Moldskred <leifm@huldreskog.localdomain> - 2014-11-15 06:11 -0600
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-11-15 03:53 -0800 |
| Subject | language lawyer request for ExecutorService |
| Message-ID | <fbfe6atfghnodror7je0hhrudh1utt0v0j@4ax.com> |
public interface ExecutorService extends Executor {
/**
* Initiates an orderly shutdown in which previously submitted
* tasks are executed, but no new tasks will be accepted.
* Invocation has no additional effect if already shut down.
*
* <p>This method does not wait for previously submitted tasks to
* complete execution. Use {@link #awaitTermination
awaitTermination}
* to do that.
*/
void shutdown();
/**
* Blocks until all tasks have completed execution after a
shutdown
* request, or the timeout occurs, or the current thread is
* interrupted, whichever happens first.
*
* @param timeout the maximum time to wait
* @param unit the time unit of the timeout argument
* @return {@code true} if this executor terminated and
* {@code false} if the timeout elapsed before termination
* @throws InterruptedException if interrupted while waiting
*/
boolean awaitTermination(long timeout, TimeUnit unit)
throws InterruptedException;
------------------
I cannot make sense of the above. Does shutdown finish previously
submitted tasks or not. The docs seem self-contradictory. By
experiment it seems not to.
To use awaitTermination, am I supposed to call shutdown first? But if
I did that, it would throw away all my pending work. What gives?
I just want to shut down normally completing all queued work.
--
Roedy Green Canadian Mind Products http://mindprod.com
Software gets slower faster than hardware gets faster.
~ Niklaus Wirth (born: 1934-02-15 age: 80) Wirth’s Law
[toc] | [next] | [standalone]
| From | Roedy Green <see_website@mindprod.com.invalid> |
|---|---|
| Date | 2014-11-15 04:04 -0800 |
| Message-ID | <j4ge6ah4gioi0bcop4pgof2g9det856ogr@4ax.com> |
| In reply to | #30356 |
On Sat, 15 Nov 2014 03:53:55 -0800, Roedy Green <see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted someone who said : >I just want to shut down normally completing all queued work. I think I get it now. Shutdown returns before finishing off the queue, but it does not empty the queue. Then you can call awaitTermination to wait for the queue to empty. It will not return until it has. -- Roedy Green Canadian Mind Products http://mindprod.com Software gets slower faster than hardware gets faster. ~ Niklaus Wirth (born: 1934-02-15 age: 80) Wirth’s Law
[toc] | [prev] | [next] | [standalone]
| From | Sebastian <news@seyweiler.dyndns.org> |
|---|---|
| Date | 2014-11-25 22:59 +0100 |
| Message-ID | <m52u46$rei$1@news.albasani.net> |
| In reply to | #30357 |
Am 15.11.2014 13:04, schrieb Roedy Green: > On Sat, 15 Nov 2014 03:53:55 -0800, Roedy Green > <see_website@mindprod.com.invalid> wrote, quoted or indirectly quoted > someone who said : > >> I just want to shut down normally completing all queued work. > > I think I get it now. Shutdown returns before finishing off the queue, > but it does not empty the queue. > > Then you can call awaitTermination to wait for the queue to empty. It > will not return until it has. > Somewhat at a tangent: I tend to avoid explicit shut down of my thread pools by supplying a ThreadFactory that produces daemon threads (the default is to use non-daemons). In event-driven scenarios I may not know when the last event has arrived and the pool can be shut down. -- Sebastian
[toc] | [prev] | [next] | [standalone]
| From | Leif Roar Moldskred <leifm@huldreskog.localdomain> |
|---|---|
| Date | 2014-11-15 06:11 -0600 |
| Message-ID | <nPadnYWSl9yR3vrJnZ2dnUVZ8hednZ2d@giganews.com> |
| In reply to | #30356 |
Roedy Green <see_website@mindprod.com.invalid> wrote:
> public interface ExecutorService extends Executor {
>
> /**
> * Initiates an orderly shutdown in which previously submitted
> * tasks are executed, but no new tasks will be accepted.
> * Invocation has no additional effect if already shut down.
> *
> * <p>This method does not wait for previously submitted tasks to
> * complete execution. Use {@link #awaitTermination
> awaitTermination}
> * to do that.
>
> */
> void shutdown();
>
>
> /**
> * Blocks until all tasks have completed execution after a
> shutdown
> * request, or the timeout occurs, or the current thread is
> * interrupted, whichever happens first.
> *
> * @param timeout the maximum time to wait
> * @param unit the time unit of the timeout argument
> * @return {@code true} if this executor terminated and
> * {@code false} if the timeout elapsed before termination
> * @throws InterruptedException if interrupted while waiting
> */
> boolean awaitTermination(long timeout, TimeUnit unit)
> throws InterruptedException;
>
> ------------------
>
> I cannot make sense of the above. Does shutdown finish previously
> submitted tasks or not. The docs seem self-contradictory. By
> experiment it seems not to.
Shutdown does not affect existing tasks -- it just stops the Executor
from adding any new tasks. The already existing tasks will keep running
until they have finished.
> To use awaitTermination, am I supposed to call shutdown first?
Yes. First you call /shutdown/, then you call /awaitTermination/
to wait for any remaining tasks to finish their work.
--
Leif Roar Moldskred
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web