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

  • SEARCH
  • Home
  • 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 6063833
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:12:45+00:00 2026-05-23T09:12:45+00:00

Can someone explain to me how Reentrant lock and deadlock relate to each other

  • 0

Can someone explain to me how Reentrant lock and deadlock relate to each other with Java code (pseudo) example?

  • 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-23T09:12:46+00:00Added an answer on May 23, 2026 at 9:12 am

    A reentrant locking mechanism allows the thread holding the lock to re-enter a critical section. This means that you can do something like this:

    public synchronized void functionOne() {
    
        // do something
    
        functionTwo();
    
        // do something else
    
        // redundant, but permitted...
        synchronized(this) {
            // do more stuff
        }    
    }
    
    public synchronized void functionTwo() {
         // do even more stuff!
    }
    

    In a non-reentrant lock, you would have a deadlock situation when you try to call functionTwo() from functionOne() because the thread would have to wait for the lock…which it holds itself.

    Deadlock, of course, is the evil situation in which Thread 1 holds lock A and is waiting for lock B while Thread 2 holds lock B and is waiting for lock A. Thus, neither can continue. This code sample creates a deadlock:

    public synchronized void deadlock() throws InterruptedException {
        Thread th = new Thread() {
            public void run() {
                deadlock();
            }
        }.start();
    
        th.join();
    }
    

    The calling thread tries to wait around for the spawned thread, which in turn can’t call deadlock() until the caller has exited. Ka-boom!

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

Sidebar

Related Questions

Can someone explain what's happening in this example code? I have a function which
Can someone explain this strange result for me? Got the following code in linqPad
Can someone explain me why this code compiles and runs fine, despite the fact
Can someone explain to me why this code fails once in a while with
Can someone explain the code below? I get confused when I try to understand
Can someone explain the question mark in the following code? Also INITIAL_PERMANCE is a
Can someone explain why in the below example the column name for why appears
Can someone explain the following code.. What will that return statement do. public byte[]
Can someone explain dependency injection with a basic .NET example and provide a few
Can someone explain why, in this example , the function is not firing? I've

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.