• 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
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Static Lock and Instance Lock

 
Greenhorn
Posts: 23
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Ranch Hand
Posts: 433
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Both these are quite easy to test, aren't they?
 
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ralph
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
No holds barred. And no bars holed. Except this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic