File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes doubt on Class synchronization ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "doubt on Class synchronization ?" Watch "doubt on Class synchronization ?" New topic
Author

doubt on Class synchronization ?

veesam sridhar
Ranch Hand

Joined: Oct 18, 2005
Posts: 51
Hi Ranchers,

I have a question on synchronization.
what happens if I write the following code.
----------------------------------------------------
public synchronized class Example{

}
----------------------------------------------------
what is the effect of the above class on its objects?

1)Can different threads create or access objects of Example class at the same time?

2)If I write the synchronized keyword for class does it mean all the static methods of the class will become synchronized? or all general methods will become syncronized?

3)If it is class level lock ,If it is class level lock does it effect on object creation process(like one thread at a time can create an object or only one object can be created for that class .... I am a bit confused ).


Please explain how the synchronization works in this particualr scenorio.

Thanks in advance,
Sridhar Veesam.















Ankith suresh
Ranch Hand

Joined: Jun 07, 2007
Posts: 42
Can we use synchronized modifier for class?
I think we can use it for methods and code block?right guys?
raj malhotra
Ranch Hand

Joined: Feb 22, 2007
Posts: 285
Yes Ankith is right!synchronized is illegal modifier for class.
only -public ,abstract and final is permitted...
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

I think sridhar seemed to be aware of the syntax error given by the compiler but still he wanted to know the effects. Am i right?

As such, you cannot see the real effects happening because the compiler stops you at the very first step during compilation by giving an error saying that


java:1: modifier synchronized not allowed here


HtH.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: doubt on Class synchronization ?
 
Similar Threads
Synchoronization at class level
Returning from synchronized
Non syncronized output even when accessing syncronized method
A static synchronized method and a non-static synchronized method will not block each other, ever.
synchronized methods and blocks worries