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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:38:02+00:00 2026-05-27T17:38:02+00:00

I have bunch of code & the processor is small, when calling notifyAll ,

  • 0

I have bunch of code & the processor is small,
when calling notifyAll, sometimes creating performance issue (100ms) so I want to know what are the threads currently waiting for the object to get released.

synchronized (obj){
//do some stuff..
obj.notifyall();
}

I want to print all the threads waiting for the object to get released before calling 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-05-27T17:38:03+00:00Added an answer on May 27, 2026 at 5:38 pm

    Are all the threads waiting on the resource for the same condition? If yes, then you can try replacing obj.notify() instead of obj.notifyAll though it really isn’t recommended. AFAIK, there is no way of “retrieving” a list of all the threads waiting on a given object (though you can programatically get a thread-dump of the process and view the threads, but I’m sure that’s not what you had in mind). Even if there was, listing threads and then doing “something” with them would surely take more than the time taken to notifyAll.

    Also, if the “processor is small”, try limiting the number of threads spawned since without a fair amount of “real” threads, creating too many threads is typically an overhead. That way, notifyAll wouldn’t wake up a bunch of threads.

    Here is a small program which demonstrates dumping of thread state information with comments inlined:

    package net.sanjayts.test;
    
    import java.lang.management.ManagementFactory;
    import java.lang.management.ThreadInfo;
    import java.util.concurrent.TimeUnit;
    
    public class ThreadDumpTest {
    
        public static void main(String[] args) throws Exception {
            final Object lock = new Object();
            for (int i = 0; i < 6; ++i) {
                final int cnt = i;
                new DaemonThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            // If counter is even, try to acquire common lock and then
                            // sleep. If odd, sleep without trying to acquire the lock.
                            // This way, if we do a thread dump, we'll see threads in
                            // different states (TIMED_WAIT for those sleeping threads
                            // and BLOCKED for those waiting for the common "lock".
                            if (cnt % 2 == 0) {
                                synchronized (lock) {
                                    TimeUnit.MINUTES.sleep(1); // sleep 1 min
                                }
                            } else {
                                TimeUnit.MINUTES.sleep(1); // sleep 1 min
                            }
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }, "mythread-" + cnt).start();
            }
            ThreadInfo[] infos = ManagementFactory.
                    getThreadMXBean().dumpAllThreads(true, true);
            for (ThreadInfo info : infos) {
                System.out.println(info);
                System.out.println("===========================");
            }
            TimeUnit.SECONDS.sleep(2);
        }
    
    }
    
    class DaemonThread extends Thread {
        public DaemonThread(Runnable r, String name) {
            super(r, name);
            setDaemon(true);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of code of the form: someVector.push_back(Foo(some name, 1.0, 3.1415926); someVector.push_back(Foo(different
I have a bunch of generic code that is used a lot, which i'd
I have a bunch of PHP code that is auto-generated and it puts all
I am fairly new to C++ and I have seen a bunch of code
I have a bunch of these little bits of HTML code repeated over and
I have a bunch of occurrences of this kind of boilerplate code in my
I have a bunch of Workflow foundation 4.0 RC code activities that consume web
I have an application with some bunch of code like this: errCode = callMainSystem();
I have a web application with bunch of HTML code. There are some style-attributes
I have a .net assembly that contains data access code (a bunch of Typed

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.