• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

doubt on Class synchronization ?

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.















 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we use synchronized modifier for class?
I think we can use it for methods and code block?right guys?
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes Ankith is right!synchronized is illegal modifier for class.
only -public ,abstract and final is permitted...
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
This looks like a job for .... legal tender! It says so right in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic