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 8042321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T04:32:20+00:00 2026-06-05T04:32:20+00:00

I need some help concerning deadlocks. I just do not understand why my code

  • 0

I need some help concerning deadlocks. I just do not understand why my code is deadlocking here.

I tried different scenarios.

However I still can’t find why and where is the problem. Normally it should work
and I don’t find where the deadlock is between debuter and termine.

  public class Interblocking {
           protected object obj = object();
           private boolean condition = true;

           public synchronized void debuter() {
               synchronized(obj) {
                   while (!condition) {
                       try {
                           obj.wait();
                       } catch (InterruptedExeption ie) {}
                   }
                   condition = false;
               }
           }

           public synchronized void terminer() {
               synchronized(obj) {
                   condition = true;
                   obj.notifyAll();
               }
           }
        }
  • 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-06-05T04:32:22+00:00Added an answer on June 5, 2026 at 4:32 am

    Edit (new answer)

    Method wait() doesn’t release all locks of current Thread.

    So when A thread invokes debuter it releases only obj lock but holds this lock so other threads can’t invoke terminer method.

    Here is example:

    class WaitReleaseTest implements Runnable {
        Object lockA, lockB;
        public WaitReleaseTest(Object lockA, Object lockB) {
            this.lockA = lockA;
            this.lockB = lockB;
        }
    
        public void run() {
            System.out.println(Thread.currentThread().getName()
                    + " attempting to acquire lockA");
            synchronized (lockA) {
                System.out.println(Thread.currentThread().getName()
                        + " attempting to acquire lockB");
                synchronized (lockB) {
                    System.out.println(Thread.currentThread().getName()
                            + " holds lockA = " + Thread.holdsLock(lockA));
                    System.out.println(Thread.currentThread().getName()
                            + " holds lockB = " + Thread.holdsLock(lockB));
                    try {
                        lockB.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    
        public static void main(String[] args) throws InterruptedException {
            Object o1=new Object();
            Object o2=new Object();
            new Thread(new WaitReleaseTest(o1,o2)).start();
            TimeUnit.MILLISECONDS.sleep(500);
            new Thread(new WaitReleaseTest(o1,o2)).start();
        }
    }
    

    output

    Thread-0 attempting to acquire lockA
    Thread-0 attempting to acquire lockB
    Thread-0 holds lockA = true
    Thread-0 holds lockB = true
    Thread-1 attempting to acquire lockA
    ... now it waits
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a little help converting some VB.NET code to C#. I have tried
Need some help understanding the difference between the success and ajaxSuccess events documented here
Need some help please with this error : TypeError : 'unicode' object does not
need some help here My problem is, my app starts with a single view,
I need some help converting an SQL query into relational algebra. Here is the
need some help! I'm trying to write some code in objective-c that requires part-of-speech
I need some help concerning nested attributes in models with 'has_one' relationship. Model Survey
I just need some help to finish turning this SQL : SELECT us.name, pt.task,
Need some help with a small problem. I'm not too hot on the maths
Need some help. This javascript code should set the target of the form and

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.