Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Threads and Synchronization
Joined: Aug 25, 2005
Oct 02, 2006 07:03:00
I have two classes (ClassA.java and ClassB.java) accessing static method (getSeq()) of a third class (ClassC.java). How do I synchronize, so that only one instance accesses the method at a time. Synchronizing on the class name doesn�t work.
author and iconoclast
Joined: Jul 08, 2003
Oct 02, 2006 07:17:00
Mark the method synchronized:
public static synchronized void getSeq() ...
That's all you need to do.
object for the class that is used as the lock -- not the name of the class.
[Jess in Action]
It is sorta covered in the
JavaRanch Style Guide
subject: Synchronizing Method
Static synchronization vs instance var synchrnisation
Couple of question about servlets and thread sync
about threads, using locks of the objects in synchronized blocks
struts and threads
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013