| 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.
|
 |
 |
|
|
subject: Synchronized
|
|
|