Synchronized in Vector

Discussion in 'Java' started by Jun, Oct 25, 2003.

  1. Jun

    Jun Guest

    I noticed that not all the public methods are synchronized.
    Some of them are even "setters" like

    public boolean remove(Object o) {
    return removeElement(o);
    }

    public void add(int index, Object element) {
    insertElementAt(element, index);
    }

    while

    public synchronized Object remove(int index) {
    ...
    }

    is syn.

    Why?

    thanks
    Jun, Oct 25, 2003
    #1
    1. Advertising

  2. Jun

    Jon Skeet Guest

    Jun <> wrote:
    > I noticed that not all the public methods are synchronized.
    > Some of them are even "setters" like
    >
    > public boolean remove(Object o) {
    > return removeElement(o);
    > }
    >
    > public void add(int index, Object element) {
    > insertElementAt(element, index);
    > }
    >
    > while
    >
    > public synchronized Object remove(int index) {
    > ..
    > }
    >
    > is syn.
    >
    > Why?


    What's the point in a method being synchronized if it does nothing but
    call precisely one other method which *is* synchronized?

    --
    Jon Skeet - <>
    http://www.pobox.com/~skeet
    If replying to the group, please do not mail me too
    Jon Skeet, Oct 25, 2003
    #2
    1. Advertising

  3. (Jun) writes:

    > public boolean remove(Object o) {
    > return removeElement(o);
    > }
    >
    > public void add(int index, Object element) {
    > insertElementAt(element, index);
    > }


    These are part of the "retrofitted" List API, and they in turn
    delegate to the old, synchronized methods.
    Tor Iver Wilhelmsen, Oct 25, 2003
    #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. Jerry
    Replies:
    4
    Views:
    131,763
    tonni
    Aug 11, 2010
  2. Pep
    Replies:
    6
    Views:
    29,241
  3. dmcreyno
    Replies:
    9
    Views:
    9,548
    Mark Space
    Jun 27, 2006
  4. Replies:
    8
    Views:
    1,896
    Csaba
    Feb 18, 2006
  5. ankur
    Replies:
    4
    Views:
    1,413
    Eric Sosman
    Nov 28, 2008
Loading...

Share This Page