File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

synchronization query

Robert Benson
Ranch Hand

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


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 ,
Roel De Nijs

Joined: Jul 19, 2004
Posts: 8384

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,

SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
I agree. Here's the link:
subject: synchronization query
jQuery in Action, 3rd edition