[concurrency-interest] Is LinkedBlockingQueue.isEmpty() thread safe?
sberlin at gmail.com
Fri Apr 20 10:54:32 EDT 2007
In the context of a bug-report snapshot, it could be useful. It could
also be useful in a variety of other ways, such as someone handing you
a LBQ that is expected to have some initial data, and then your code
is intended to spawn threads to work on the items in that queue. Your
code could query the size and throw an exception if it doesn't have
the expected number of elements.
On 4/20/07, Szabolcs Ferenczi <szabolcs.ferenczi at gmail.com> wrote:
> On 20/04/07, Kasper Nielsen <kasper at kav.dk> wrote:
> > Yes it is thread safe. And what exactly makes you wonder if it isn't?
> 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
> threads. You can query whether it is empty, but you cannot do anything
> with the result. Either isEmpty() yields true or false, anything can
> be the case. The queue can even be full at the very time the isEmpty
> returns true.
> So we can conclude this method on LBQ is something that can be
> classified as YAGNI.
> Can anyone show a meaningful use of that query in a multithreading environment?
> Best Regards,
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
More information about the Concurrency-interest