difference between add and offer on ConcurrentLinkedQueue

Discussion in 'Java' started by marlow.andrew@googlemail.com, Oct 21, 2008.

  1. Guest

    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
     
    , Oct 21, 2008
    #1
    1. Advertising

  2. Lew Guest

    On Oct 21, 3:49 pm, wrote:
    > 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?


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

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

    --
    Lew
     
    Lew, Oct 21, 2008
    #2
    1. Advertising

  3. Guest

    On 21 Oct, 20:58, Lew <> wrote:
    > On Oct 21, 3:49 pm, wrote:
    >
    > > 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?

    >
    > 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
     
    , Oct 22, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jakk
    Replies:
    4
    Views:
    12,603
  2. Quaid
    Replies:
    0
    Views:
    569
    Quaid
    Jun 5, 2006
  3. Santa
    Replies:
    1
    Views:
    1,153
    Mark A. Odell
    Jul 17, 2003
  4. Joe Seigh

    ConcurrentLinkedQueue question

    Joe Seigh, Jan 6, 2007, in forum: Java
    Replies:
    11
    Views:
    822
    Robert Klemme
    Jan 7, 2007
  5. PerlFAQ Server
    Replies:
    0
    Views:
    393
    PerlFAQ Server
    Jan 6, 2011
Loading...

Share This Page