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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T18:32:06+00:00 2026-05-23T18:32:06+00:00

Well, I was wrong – the stating below does not apply, not in my

  • 0

Well, I was wrong – the stating below does not apply, not in my test runs.


This mail (wot, no chickens?) from the the Java Thread mailing list is quite old, in fact it’s from 25th September 1996. Peter Welch has found out:

Enclosed is a demonstration that shows that notified threads do get
put on the back of the queue in order to regain the monitor. Before
the `wait’ method returns, the thread is made to queue up again on the
monitor (behind threads that arrived long after it first went through
that queue!). This can result in infinite overtaking and, hence,
thread starvation.

To summarize the behavior again:

Thread-1 acquires the monitor lock
Thread-1 sees the condition is not true yet -> wait()
Thread-0 acquires the monitor lock
Thread-2 contends with Thread-0 for the monitor lock
Thread-3 contends with Thread-0 for the monitor lock
Thread-4 contends with Thread-0 for the monitor lock
Thread-5 contends with Thread-0 for the monitor lock
Thread-0 turns the condition to true -> notifyAll();
Thread-0 released the monitor lock
Thread-4 acquires the monitor lock
Thread-4 enjoys his desirable state
Thread-4 releases the monitor lock
Thread-2 acquires the monitor lock
Thread-2 enjoys his desirable state
...

The thread being the first one to wait on the condition will never be the first one to regain the monitor. I knew already, that there is no fairness guarantee. What, however, is new to me, is that there is some kind of order in how the threads regain the monitor.

Why should the first thread be the one to regain the monitor lock the last? The way it’s implemented Thread-1 is never able to pass the condition and get into the desired state.

Is there some explanation for this semantic?

Important: This question is not about, whether I can rely on the mechanics I’ve discovered. I know how the waiting and signalling for Java is documented and that they clearly state, you cannot rely on this. What I am interested in, whether virtual machines implement it in this way, whether they order the threads in this certain way.

  • 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-23T18:32:06+00:00Added an answer on May 23, 2026 at 6:32 pm

    The ordering is going to be JVM specific if you are using Object’s wait/notify. The javadoc for the notify method states:

    Wakes up a single thread that is waiting on this object's monitor. If any threads are
    waiting on this object, one of them is chosen to be awakened. The choice is arbitrary and 
    occurs at the discretion of the implementation. A thread waits on an object's monitor by 
    calling one of the wait methods.
    

    However, a ReentrantReadWriteLock does support a fairness policy, and fair mode is described as:

    When constructed as fair, threads contend for entry using an approximately arrival
    order policy. When the currently held lock is released either the longest-waiting
    single writer thread will be assigned the write lock, or if there is a group of reader
    threads waiting longer than all waiting writer threads, that group will be assigned the read lock.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well, this doesn't really refer to the wrong object, but I do not know
I posted this on serverfault as well, but I probably asked in the wrong
//Difference between 2 dates This function works well but display wrong time format. Pls
Why is this copy(click) wrong, it binds all the previous handlers as well: var
I'm not sure whats wrong with this it says incompatible implicit built in func
So, I thought this would be simple and, well, I was wrong. Here is
Ok, so maybe my search syntax is wrong here, this could have very well
Well, I don't know if I'm completely wrong, but I really can't find a
Well, this is my first post here and really enjoying the site. I have
Well this is incredibly frustrating. After being nagged by Rails that I need to

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.