• Post Reply Bookmark Topic Watch Topic
  • New Topic

Synchronizing Method

 
Pradeep Swaminathan
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!