Synchronization

Discussion in 'Java' started by sangeetay@gmail.com, Oct 3, 2005.

  1. Guest

    hi ,
    i would like to know hwta happens in this scenerio..
    if a synchronized method calls an unsynchronized method. Does the
    unsynchronized method behave as if it is synchronized automatically..
     
    , Oct 3, 2005
    #1
    1. Advertising

  2. On 3 Oct 2005 00:27:17 -0700, wrote:
    > if a synchronized method calls an unsynchronized method. Does the
    > unsynchronized method behave as if it is synchronized automatically..


    Some pseudo code and names will help here:

    public synchronized void outer() {
    System.out.println("this method is synchronized");
    /* some code... */
    inner();
    /* more code... */
    }

    public void inner() {
    System.out.println("this method is unsynchronized");
    /* some code... */
    }

    Only outer() is synchronized, and others are still free to call
    inner() directly. Realize though that the original thread does not
    leave outer() when it calls inner(), so outer() is still protected by
    the synchronization during the time it executes inside inner().

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Oct 3, 2005
    #2
    1. Advertising

  3. Roedy Green Guest

    On 3 Oct 2005 00:27:17 -0700, wrote or quoted :

    > i would like to know hwta happens in this scenerio..
    > if a synchronized method calls an unsynchronized method. Does the
    >unsynchronized method behave as if it is synchronized automatically..


    It isn't unless there are no direct calls to the unsynchronised
    method.

    By analogy if you have a guard checking everyone coming into building,
    you don't need one on every door once they get in.

    The guard at the front door only lets one person into the building at
    a time. There is no way than visitor can bump into any other people,
    even if there are no such guards ensuring no more than one person to a
    room.

    synchronisation is like a guard ensuring but one thread at a time can
    enter a region of code.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Again taking new Java programming contracts.
     
    Roedy Green, Oct 3, 2005
    #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. arcvonz

    System Time synchronization

    arcvonz, Aug 23, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    488
    Sam Santiago
    Aug 23, 2004
  2. John

    Flip Flop Synchronization

    John, Jan 3, 2004, in forum: VHDL
    Replies:
    3
    Views:
    9,791
    valentin tihomirov
    Jan 5, 2004
  3. Simon
    Replies:
    1
    Views:
    640
    tbx135
    Jan 9, 2004
  4. prav

    regarding synchronization

    prav, Feb 18, 2004, in forum: VHDL
    Replies:
    5
    Views:
    1,308
    Jos De Laender
    Feb 21, 2004
  5. deep
    Replies:
    0
    Views:
    480
Loading...

Share This Page