This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Synchronized Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Synchronized" Watch "Synchronized" New topic
Author

Synchronized

Shubha Krishna
Greenhorn

Joined: Aug 18, 2006
Posts: 13
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

Joined: Dec 11, 2004
Posts: 13410

Moving to Java In General (intermediate).
This forum is for Servlet questions.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ilja Preuss
author
Sheriff

Joined: Jul 11, 2001
Posts: 14112
Have you tried? I'd bet that you get a compile time error when you do...


The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Brian Mozhdehi
Ranch Hand

Joined: Aug 17, 2006
Posts: 81
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Synchronized
 
Similar Threads
Synchronized and UML
Could Class be synchronized ?
Can Overloaded method be synchronized
can a Class be synchronized?
Sychronized class