• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

class lock

 
Ranch Hand
Posts: 280
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Kapil to this forum
1.What is actually a class lock?
I suppose if a thread is executing a static synchronized method,
it gets the class lock.
So does this mean that if a thread gets a class lock, no other thread can execute any synchronized method on any object of that lock?
2.CardLayout is not in SCJP exam,can you confirm.In RHE CardLayout is also explained.
Thanx in advance
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Leena,
Just like shared methods and objects classes also have a monitor or a semaphore. So when a thread is invoking a static synchtonized method it acquires the monitor of that class and hence locks the class. Thus , other threads can not access this particular class. The non synchronized methods though can be invoked by other threads.
If u refer Khalid Mughal's book on (page 281 - first para) he clearly has mentioned that "A thread acquiring the monitor of a class to execute a static synchronized mrthod has no bearing on any thread acquiring the monitor on any object of the class to execute a sunchronized instance method"
Correct me if i am wrong.
 
Tejas Tambe
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
plase ommit the statement - "Thus , other threads can not access this particular class. " from my earlier reply.
Sorry for the incorrect statement
 
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tejas,
Class locks/monitors has nuthing to do with the object lock
A thread can have an object's lock and work on synchronized instance method, while another thread work on synchronized static class method with a class montior
In a word, they are both independent of each other
Ragu
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!