Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Static Lock and Instance Lock

 
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

 
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 ?
 
Rancher
Posts: 43016
76
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
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.
 
We should throw him a surprise party. It will cheer him up. We can use this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic