aspose file tools*
The moose likes Threads and Synchronization and the fly likes What is Reentrancy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "What is Reentrancy?" Watch "What is Reentrancy?" New topic
Author

What is Reentrancy?

Shaik Muhammad
Ranch Hand

Joined: Jul 16, 2008
Posts: 36

What is Reentrancy? How does Reentrant lock differ from ordinary synchronized block. pl explain
Nitesh Kant
Bartender

Joined: Feb 25, 2007
Posts: 1638

Reentrancy as the name suggests is the process of entering into a place again!

W.R.T locks, it is the time when a thread wants to reacquire the same lock.

So, if i say,



If reentrancy is not allowed then the above code will result in a deadlock as the thread is trying to acquire a lock which is already acquired.

Synchronized block is also reentrant. ReentrantLocks are named in such a way to be explicit about the nature of the lock.


apigee, a better way to API!
luri ron
Ranch Hand

Joined: Dec 11, 2008
Posts: 87
one obivious diffrence between synchronized and reentrantlock is that you can have control how to lock it (you can use trylock) and the policy (fair or not fair) to lock it. the java doc should provide the details.
 
 
subject: What is Reentrancy?