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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:41:10+00:00 2026-06-18T01:41:10+00:00

What is the cost associated with calling notify() on an Object on which no

  • 0

What is the cost associated with calling notify() on an Object on which no other Objects have called wait() in Java?

The reason I am interested in this is because I have a worker thread that has a queue of Objects.

The thread loops continuously checking if it has any Objects in the queue that it needs to work with. If it loops and there is nothing in said queue the thread calls wait on on a separate Object.

When another thread adds an Object to the queue it calls notify on the Object that the worker thread would be waiting on regardless if the working thread is actually waiting.

Before anyone says anything, it is all synchronized correctly and won’t throw any exceptions/errors.

My question is: is this setup slower then just having the worker thread just continue checking and never call wait() and what is the cost of calling notify() without any threads waiting on the Object?

Thanks for the help in advance 🙂

  • 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-18T01:41:11+00:00Added an answer on June 18, 2026 at 1:41 am

    If you don’t block worker thread, it’ll be a busy-wait “spinloop” pattern, e.g. something like:

    while (queue.isEmpty()) {
      Thread.yield();
    }
    

    I’ve been reading about this model of conditional waiting today (in regards of my own problem :)) and found the following notes about when such model might show superior performance to ordinary wait() – notify() scheme:

    … The main exceptions are those cases in which you somehow know that the condition must become true within some very short, boudned amount of time. In such cases, the time wasted spinning might be less than the time required to suspend and resume threads.

    The book is “Concurrent Programming in Java: Design Principles and Patterns” by Doug Lea.

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

Sidebar

Related Questions

SQL Server 2008. I have this very large query which has a high cost
In this scenario, every sales order is going to have atleast 400-500 products associated
I have a web application which calls WCF service to get an object. I
I have a custom field associated with user which stores the score of each
Is there a cost associated with overloading methods in .Net? So if I have
The following method calculates cost. It access other classes when required. Cloud class holds
I have a cost optimization request that I don't know how if there is
Just wonder how much cost to raise a java exception (or to call native
In one of my Java 6 projects I have an array of LinkedHashMap instances
For each product there are associated cost calculators like: discount, discount by merchant, bonus

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.