Profile Image
iftekhar.khan

Issue: High Thread Count with WAITING (Parking) State

I have 6000 threads, all in the WAITING (parking) state, with the last executed method being:

java.lang.Thread.State: WAITING (parking)

    at jdk.internal.misc.Unsafe.park(java.base@11.0.22/Native Method)

Stack Trace:

java.lang.Thread.State: WAITING (parking)

    at jdk.internal.misc.Unsafe.park(java.base@11.0.22/Native Method)

    - parking to wait for <0x00000000c6a3c678> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)

    at java.util.concurrent.locks.LockSupport.park(java.base@11.0.22/LockSupport.java:194)

    at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(java.base@11.0.22/AbstractQueuedSynchronizer.java:2081)

    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(java.base@11.0.22/ScheduledThreadPoolExecutor.java:1177)

    at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(java.base@11.0.22/ScheduledThreadPoolExecutor.java:899)

    at java.util.concurrent.ThreadPoolExecutor.getTask(java.base@11.0.22/ThreadPoolExecutor.java:1054)

    at java.util.concurrent.ThreadPoolExecutor.runWorker(java.base@11.0.22/ThreadPoolExecutor.java:1114)

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(java.base@11.0.22/ThreadPoolExecutor.java:628)

    at java.lang.Thread.run(java.base@11.0.22/Thread.java:829)

Issue Details:

  • The stack trace does not contain any direct reference to my application code.
  • The threads are waiting inside a ScheduledThreadPoolExecutor's queue, specifically in DelayedWorkQueue.take().
  • This suggests they are waiting for scheduled tasks to be executed.

How to Debug Further?

    Please Sign In or to post your comment or answer

    Profile Image

    Unni Mana

     

    Hello iftekhar.khan

    Unfortunately you cannot do much here because this is the bottom stack of the code execution. The current stack trace is the internal implementation of Java for executing threads.

    But you can check why there are 6000 threads required at this point (all are really waiting for some job!). This is a huge count. You may want to revisit the existing thread pool size.

     

    Profile Image

    Kousika M


    Hello iftekhar.khan,

    Greetings!

    There might be an issue with thread pool configuration or task scheduling. You can try to  Check Thread Pool Configuration, reduce the thread pool size and monitor behavior. 

    An excessively large pool may lead to unnecessary threads waiting indefinitely.

     

    Inspect the task submission logic to ensure tasks are being scheduled and executed correctly. If tasks are getting canceled or failing silently, the threads may remain in a waiting state without performing any useful work.


    Check if the queue has tasks.A consistently empty queue with a high thread count may indicate an issue with task scheduling. Suppose If the queue size is 0, tasks might not be getting submitted correctly.

    Monitoring thread states over time can help. Revisiting the thread pool size and ensuring proper thread reuse could help mitigate this issue.

    Thanks.

     

    Got something else on mind? Post Your Question