wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes synchronization query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "synchronization query" Watch "synchronization query" New topic
Author

synchronization query

Robert Benson
Ranch Hand

Joined: Apr 04, 2010
Posts: 56
Hi,
I just want to nail down my understanding of synchronization, I've got two questions:


Q1/

Method A Synchronized
Method B (not marked as synchronized)
Method C (not marked as synchronized)

Methods B & C are in different classes


If method A is synchronized and method A calls B, which in turn calls C, does the whole chain become synchronized(A,B&C)?

My program does this, but B is only called by A. I assume this is safe and Synchronized?

Q2/ Is there a difference between the following. One uses Synchronization, the other locks. To me they both do the same thing, but example 1 is cleaner and less error prone:

e.g. 1


e.g. 2


Thanks, Robert.

SCJP 6 , OCMJD 6 ,
http://www.robertbenson.ie/
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5154
    
  12

Hi Robert,

Q1/ it depends. If method B (and C) are called from other methods than method A, methods B and C will not be synchronized.

Q2/ if you want to synchronize your complete method, then example 1 certainly does the job in the easiest way possible.

Kind regards,
Roel


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: synchronization query
 
Similar Threads
URLybird
pls validate my locking strategy - all inputs are g8ly appreciated. (URLyBird)
Methods in RMI and Multithreading
My locking approach...comments please
delete() and unlock()