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

What is Reentrancy?

 
Shaik Muhammad
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

What is Reentrancy? How does Reentrant lock differ from ordinary synchronized block. pl explain
 
Nitesh Kant
Bartender
Posts: 1638
IntelliJ IDE Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
luri ron
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic