• 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

questions

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a questions regarding the SCJP exam:

1.
Can a static method be synchronized? If so, what is being locked
since there is no this reference?

2.
I thought one object has only one lock. Is that
not true?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1.) Yes static methods can be syncronised.
they are synchronized on the class
eg-syncronized(<class name>

2.)Yes each object has only one lock
 
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

Originally posted by Anne Sullivan:
I have a questions regarding the SCJP exam:

1.
Can a static method be synchronized? If so, what is being locked
since there is no this reference?



From Kathy Sierra's and Bert Bate's SCJP book,


Static
methods can be synchronized. There is only one copy of the static data you�re trying
to protect, so you only need one lock per class to synchronize static methods�a lock
for the whole class. There is such a lock; every class loaded in Java has a corresponding
instance of java.lang.Class representing that class. It�s that java.lang.Class instance
whose lock is used to protect the static methods of the class (if they�re synchronized).



Hope this clears!
 
These are not the droids you are looking for. Perhaps I can interest you in a tiny ad?
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic