This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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.
 
Consider Paul's rocket mass heater.
 
subject: What is Reentrancy?
 
Similar Threads
BeanNotReentrantException
JNI + interrupts handling
problems with reentrancy
NX: Assignment - some design questions
Reentrancy