File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Developer Certification (SCJD/OCMJD)
Joined: Apr 04, 2010
Oct 09, 2010 10:03:03
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:
public synchronized updateRoom(int recNo, String data)
public updateRoom(int recNo, String data) lock.lock(); other code lock.unlock();
SCJP 6 , OCMJD 6 ,
Roel De Nijs
Joined: Jul 19, 2004
Oct 09, 2010 17:27:36
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.
, SCJP (
With a little knowledge, a
cast iron skillet
is non-stick and lasts a lifetime.
subject: synchronization query
pls validate my locking strategy - all inputs are g8ly appreciated. (URLyBird)
delete() and unlock()
My locking approach...comments please
Methods in RMI and Multithreading
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013