• Post Reply Bookmark Topic Watch Topic
  • New Topic

Static Lock and Instance Lock  RSS feed

 
Raveendran Hs
Greenhorn
Posts: 23
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1: When One Thread holding Static lock(Class lock) on a Class then is it possible for another Thread to acquire Instance lock of this class
Q2: When One Thread holding the Instance lock then is it possible for another Thread to acquire Static lock(Class lock) on this class

 
Deepak Chopra
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you planning to have a static lock, I mean lock over a class?

I believe you can always have a lock over class instance or Do you mean to say - lock over static properties of a class?

Beside you code doesn't have run method, so Its difficult to know what are you trying to do ?
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both these are quite easy to test, aren't they?
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A static lock on a class is not related to any instance lock. It is a lock on the class object, and as far as instances of that object go, it is just a separate object.

To the other reply-er -- a method declared static synchronized locks the class object, not any instance object; that's what the OP means (I presume) by a static lock.

rc
 
Raveendran Hs
Greenhorn
Posts: 23
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ralph
 
samaya muduli
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
]
Sunny Jain wrote:How are you planning to have a static lock, I mean lock over a class?

I believe you can always have a lock over class instance or Do you mean to say - lock over static properties of a class?

Beside you code doesn't have run method, so Its difficult to know what are you trying to do ?




See the results and then remove the static from the method signature of display and then compare with last output.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!