[concurrency-interest] Hung progress in ThreadPoolExecutor ExecutorCompletionService when slave threads killed.
davidcholmes at aapt.net.au
Mon May 14 01:23:37 EDT 2012
Dr Heinz M. Kabutz writes:
> When you stop() a thread that has called wait(), it first reacquires
> the monitor before bailing out. The monitor is then automatically
> unlocked again when you leave the scope.
This is possible because the monitor reacquisition happens in the VM's
native code, not part of any Java code sequence.
> However, Condition.await() does *not* reacquire the lock when you
> stop() the thread. When unlock() is then called on Lock as you exit
> the scope, an IllegalMonitorStateException is then thrown. I would
> love to know if that is deliberate or a coding bug?
It is unavoidable due to the fact this is implemented in Java code. People
will say "put the lock re-acquisition in a finally block, that will fix it",
but that will only fix the case where the stop() hits while the thread is
actually blocked. If the stop() hits during any of the queue management code
you can easily get corrupt data structures.
It is impractical, if not impossible, to non-trivial write async-exception
> Anyway, my bet is that this is the culprit. You can also see the
> await() method in the stack trace.
> On 14/05/2012, Zhong Yu <zhong.j.yu at gmail.com> wrote:
> > If an exception can occur any where any time, it is impossible to
> > write code that can survive it and maintain invariants.
> > lock
> > x++;
> > y++;
> > unlock
> > If we have to worry that some exception may be thrown between x++ and
> > y++, we cannot write any program at all.
> > ThreadDeath is exactly such an exception.
> > Others include OutOfMemoryError and StackOverflowError - they are more
> > predictable, but still, we cannot afford to worry about them on every
> > `new` and every method call.
> > Zhong Yu
> > _______________________________________________
> > Concurrency-interest mailing list
> > Concurrency-interest at cs.oswego.edu
> > http://cs.oswego.edu/mailman/listinfo/concurrency-interest
> Dr Heinz M. Kabutz (PhD CompSci)
> Author of "The Java(tm) Specialists' Newsletter"
> Sun Java Champion
> IEEE Certified Software Development Professional
> Tel: +30 69 75 595 262
> Skype: kabutz
> Concurrency-interest mailing list
> Concurrency-interest at cs.oswego.edu
More information about the Concurrency-interest