Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2005

Tip: Looking for answers? Try searching our database.

Synchronization

Thread view: 
sangeetay@gmail.com - 03 Oct 2005 08:27 GMT
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..
Gordon Beaton - 03 Oct 2005 09:00 GMT
>  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

Signature

[  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

Roedy Green - 03 Oct 2005 09:54 GMT
> 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.
Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Again taking new Java programming contracts.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.