[concurrency-interest] Is LinkedBlockingQueue.isEmpty() thread safe?

Holger Hoffstätte holger at wizards.de
Fri Apr 20 10:27:38 EDT 2007

Szabolcs Ferenczi wrote:
> I was wondering whether it was planned to be used in a multi-threading
> environment. Now, although it is thread safe in the sense that it does
> not brake anything in the shared data structure, it is a useless
> method for a data structure that is designed to be used by concurrent

No, it is not. Since Java does not allow one to actually remove methods in
subclasses, the only way is to let the user determine on whether the
method makes sense in a certain context. Should a concurrent class'
isEmpty() throw MightBeStaleStateException instead?
If you want a language with better compositional qualities on the method
level, try Self or try to fix the Java collection classes to not use
inheritance for roles & capabilities - which will never happen.


More information about the Concurrency-interest mailing list