aspose file tools*
The moose likes Beginning Java and the fly likes Intrinsic lock? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Intrinsic lock?" Watch "Intrinsic lock?" New topic
Author

Intrinsic lock?

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

"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?



Jon
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18981
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

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
Sheriff

Joined: Sep 28, 2004
Posts: 18981
    
  40

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Intrinsic lock?