File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronized

 
Shubha Krishna
Greenhorn
Posts: 13
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can we use Synchronized keyword against a class? What happens when a class gets synchronized? Waiting for the answer. Thanks in advance.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to Java In General (intermediate).
This forum is for Servlet questions.
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried? I'd bet that you get a compile time error when you do...
 
Brian Mozhdehi
Ranch Hand
Posts: 81
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Shubha....what are trying to accomplish with this? If you want all actions of the class to be locked in a single thread, then just modify all public methods of the class with synchronized. If you want a single instance of the class to be shared accross all other objects in your system, then declare the constructor protected and use static synchronized for all public methods and static for all protected/private methods and attributes.

As indicated above, the class itself cannot be "synchronized". But, the point is, whatever you are trying to do, there is a mechanism available to do it.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic