• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

can a Class be synchronized?

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

I would like to know whether a class can be synchronized or not !!! plz provide some info as this was asked in an interview..plz provide me some examples..


Waiting for ur coments,and suggestions...

[EFH: One question mark in the subject is plenty, thanks. ]
[ July 19, 2006: Message edited by: Ernest Friedman-Hill ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, the 'synchronized' keyword cannot be applied to a class, only to methods and to synchronized blocks.
 
Vijay Kumar koganti
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx for ur Reply,

Does every loaded class has a key? As u said that synchronized keyword can not be used with class but is there any way we can synchronize a Class...

Thanks, in Advance,
vj
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot "synchronize a class" -- I don't know what that would even mean -- but static methods are synchronized using the java.lang.Class instance for the class in which the appear. In this sense they are synchronized "on the class".
 
Vijay Kumar koganti
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thx for ur prompt reply...My doubt is resolved, i just wanted to confrim this one to make sure that i am not wr0ng...


Thx a lot...
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, be aware that people may informally use the term "synchronized class" to refer to a class whose methods are all synchronized, like Vector for example. Personally I would avoid such usage as it's ambiguous - but if someone else uses the term, it's useful to consider that this may be what they meant.
reply
    Bookmark Topic Watch Topic
  • New Topic