• 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Can "synchronized" be used with a class?

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can we use "synchronized" modifier with the class definition?
If so, what is the effect of it on the class?

Thanks
Ashok
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For a class definition only public, abstract & final are permitted.
we use synchronized modifier for only methods and blocks.

Thanks
Vishnu
 
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
all the non-inner class modifiers allwoed are : public ,default(package access), abdtract , final, strictp
both abstract & final not allowed....

for more info: ch#1 of scjp5 for K&B....
bye,,,,
[ April 13, 2006: Message edited by: ali tareq ]
 
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
just a guess

Synchronise is used when a single thread can acces the variable or method.

the reason behind that is to make application threadsafe and modifications can be done one at a time with consistent results....

Making class syncronise doesnt server any purpose as clas contains methods and variable which can be access by different threads at a sametime.hence making variables and methods syncronise make sense...

correct me if i am wrong...

thank you.
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Synchronise is used when a single thread can acces the variable or method.

Synchronise is used in only methods not variables..
the reason behind that is to make application threadsafe and modifications can be done one at a time with consistent results
 
A day job? In an office? My worst nightmare! Comfort me tiny ad!
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic