Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic