wood burning stoves
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Thread's Locks Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Thread Watch "Thread New topic

Thread's Locks

Shishio San
Ranch Hand

Joined: Aug 29, 2002
Posts: 223
How would this be intersting ?!!
Any ideas ?

14.18 The synchronized Statement
A single thread may hold a lock more than once.
The example:

class Test {
public static void main(String[] args) {
Test t = new Test();
synchronized(t) {
synchronized(t) {
System.out.println("made it!");
made it!
This example would deadlock if a single thread were not permitted to lock a lock more than once.

Whatever doesn't kill us ...<br />Is probably circling back for another try.<br />SCJP 1.4
Valentin Crettaz
Gold Digger

Joined: Aug 26, 2001
Posts: 7610
If a single thread was not be able to acquire the same lock multiple times, it would not be permitted to invoke a synchronized method from the body of another synchronized method of the same class. In clear, one thread is allowed to lock the same lock multiple times. The lock is released when a equal amount of unlock actions have been performed.
Please refer to JLS 17.5 Rules about Locks for detailed information about how un/locking works.

[Blog] [Blogroll] [My Reviews] My Linked In
I agree. Here's the link: http://aspose.com/file-tools
subject: Thread's Locks
It's not a secret anymore!