• Post Reply Bookmark Topic Watch Topic
  • New Topic

can a Class be synchronized?

 
Vijay Kumar koganti
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • 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 ]
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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
Sheriff
Posts: 24213
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • 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
  • 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...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!