Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Synchronization

Reply
Thread Tools

Synchronization

 
 
sangeetay@gmail.com
Guest
Posts: n/a
 
      10-03-2005
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..

 
Reply With Quote
 
 
 
 
Gordon Beaton
Guest
Posts: n/a
 
      10-03-2005
On 3 Oct 2005 00:27:17 -0700, http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
 
 
 
Roedy Green
Guest
Posts: n/a
 
      10-03-2005
On 3 Oct 2005 00:27:17 -0700, (E-Mail Removed) 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
synchronization Firefox 0 04-12-2005 03:44 PM
System Time synchronization arcvonz ASP .Net 2 08-23-2004 10:17 PM
regarding synchronization prav VHDL 5 02-21-2004 10:14 AM
More synchronization problems Simon VHDL 1 01-09-2004 04:20 PM
Flip Flop Synchronization John VHDL 3 01-05-2004 05:58 PM



Advertisments