Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Intrinsic lock?

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Suppose d is the object we're using to invoke wait. When a thread invokes d.wait, it must own the intrinsic lock for d — otherwise an error is thrown. Invoking wait inside a synchronized method is a simple way to acquire the intrinsic lock."

Sourced from here.

How would you code the assertion that a thread owns an intrinsic lock?

 
Henry Wong
author
Marshal
Pie
Posts: 21122
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Camilleri wrote:
How would you code the assertion that a thread owns an intrinsic lock?


The Thread class has a holdsLock() method. This method can be use to check if a thread owns the lock -- and interestingly, the JavaDoc specifically provides an example of it as an assertion.

Henry
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Jon Camilleri wrote:
How would you code the assertion that a thread owns an intrinsic lock?


The Thread class has a holdsLock() method. This method can be use to check if a thread owns the lock -- and interestingly, the JavaDoc specifically provides an example of it as an assertion.

Henry


I had no idea where to look, so I must be starting to think like a Java programmer
 
Henry Wong
author
Marshal
Pie
Posts: 21122
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jon Camilleri wrote:
I had no idea where to look, so I must be starting to think like a Java programmer



See java.lang.Thread


And I don't know what you mean by the "starting to think like a Java programmer" part.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic