difference between add and offer on ConcurrentLinkedQueue

M

marlow.andrew

Hello guys,

I wonder, can anyone tell me the difference between the add and offer
methods on ConcurrentLinkedQueue? They both seem to put the specified
item on the end of the queue. That's what I want to do, so which
method do I use? Does it matter? Why are there two?

Regards,

Andrew Marlow
 
M

marlow.andrew

Have you considered reading the Javadocs?  You should always read the
Javadocs.

<http://java.sun.com/javase/6/docs/api/java/util/Queue.html>

I did read the javadoc for ConcurrentLinkedQueue but I only found
minimal information there for the descriptions of add and offer. I
didn't realise the real documentation for those methods was in Queue.
But now I know. Thanks for the pointer. Here is what I found:

---
The offer method inserts an element if possible, otherwise returning
false. This differs from the Collection.add method, which can fail to
add an element only by throwing an unchecked exception. The offer
method is designed for use when failure is a normal, rather than
exceptional occurrence, for example, in fixed-capacity (or "bounded")
queues.
---

So this tells me that 'add' is what I want in this case. Thanks for
making me look more carefully at the javadocs. Being from a C++
background I am more used to doxygen than javadoc. In doxygen the
method documentation is inherited. That's why I didn't bother going to
the Queue documentation for those methods.

Regards,

Andrew Marlow
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top