aspose file tools
The moose likes Threads and Synchronization and the fly likes Synchronizing  Method Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Synchronizing  Method " Watch "Synchronizing  Method " New topic
Author

Synchronizing Method

Pradeep Swaminathan
Greenhorn

Joined: Aug 25, 2005
Posts: 8
Hi,

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.

Thanks�
Pradeep


Pradeep
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24039
    
  13

Mark the method synchronized:

public static synchronized void getSeq() ...

That's all you need to do.

It's the java.lang.Class object for the class that is used as the lock -- not the name of the class.


[Jess in Action][AskingGoodQuestions]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Synchronizing Method
 
Similar Threads
Couple of question about servlets and thread sync
about threads, using locks of the objects in synchronized blocks
Static synchronization vs instance var synchrnisation
struts and threads
VICTORY: Locking