Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7032619
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:57:31+00:00 2026-05-28T00:57:31+00:00

Possible Duplicate: Synchronization vs Lock I am wondering is there big difference in using

  • 0

Possible Duplicate:
Synchronization vs Lock

I am wondering is there big difference in using ReentrentLock and Synchronized(object)?

Why it is called reentrentLock? to permit recurive call from the same thread?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T00:57:32+00:00Added an answer on May 28, 2026 at 12:57 am

    I am wondering is there big difference in using ReentrantLock and synchronized (object).

    The main differences are:

    • With synchronized the locking / unlocking is tied to the block structure of your source code. A synchronized lock will be released when you exit the block, no matter how you do this. For instance, it will be released if the block terminates due to an unexpected exception.

      With explicit locking this is not the case, so you could acquire a ReentrantLock (or any other Lock) in one method and release it in another one. But the flip side is that you must remember to explicitly release the Lock at the appropriate time / place. If you don’t you’ll end up with a stuck lock, and (maybe) deadlocks. In short, ReentrantLock is more complicated and potentially more error prone.

    • The primitive locking that you get with synchronized works with Object.wait() and Object.notify(). Locks don’t.

    • A ReentrantLock can be created to be “fair”, which means that threads that are waiting to acquire a given lock will acquire the lock in fifo order. Primitive locks are not fair.

    • The ReentrantLock API has methods that can be used to test whether the lock is in use, find out the length of the lock queue, try to acquire the lock without blocking, and various other things. None of this functionality is available for primitive locks.

    Why it is called a reentrant lock? to permit recursive call from the same thread?

    A reentrant lock allows a thread that is holding a lock to acquire it again. One of the ways that this could happen is through recursion, but there are others too.

    For the record, synchronized locks are also reentrant, so you don’t need to worry about recursion, or other scenarios where a thread might acquire a lock it already holds.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Threads synchronization. How exactly lock makes access to memory 'correct'? This question
Possible Duplicate: How do you send email from a Java app using Gmail? How
Possible Duplicate: How do I get the current state of Caps Lock in VB.NET?
Possible Duplicate: Binary representation of a number in Matlab I am using matlab and
Possible Duplicate: Is there some ninja trick to make a variable constant after its
Possible Duplicate: Can you write object oriented code in C? Hi, can someone point
Possible Duplicate: Reading through file using ifstream I'm trying to find a way to
Possible Duplicate: Where can I find a web-project “security checklist?” i was just wondering
Possible Duplicate: Java Synchronization I'm reading the book Beginning Android Games . It uses
Possible Duplicate: Create Generic method constraining T to an Enum Is there any reason

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.