How much resources do sleeping and waiting threads consume
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.
Introduction
In multi-threaded programming, resources management is crucial for maintaining the efficiency and performance of applications. Threads are sequences of programmed instructions that can be managed independently by a scheduler. In the lifecycle of a thread, it can be in one of several states - among these states are `sleeping` and `waiting`. Understanding how much resources these states consume is key to optimizing application performance and ensuring resources are efficiently allocated.
Thread States Overview
Threads in a typical program can be in one of these states:
- New: The thread is created but not yet started.
- Runnable: The thread is executing in the Java virtual machine but it may be waiting for other resources such as processor time.
- Blocked: The thread is waiting for a monitor lock to enter a synchronized block/method.
- Waiting: The thread is waiting indefinitely for another thread to perform a particular action.
- Timed Waiting: The thread is waiting for another thread to perform a particular action for up to a specified waiting time.
- Terminated: The thread has completed its execution.
Among these, `sleeping` and `waiting` are states where threads are not actively executing but still hold some level of resource allocation.
Sleeping Threads
Definition
A thread goes into a "sleeping" state when a method such as `Thread.sleep(milliseconds)` is invoked. This means that the thread pauses execution for a specific amount of time.
Resource Consumption
- CPU Usage: Sleeping threads do not use CPU cycles as their execution is paused. However, they still remain part of the system's ready queue until they wake up.
- Memory Footprint: They hold onto the memory resources used during their execution, such as stack and heap memory, since they are paused, not terminated.
- Synchronization: Do not hold locks unless explicitly programmed to do so at the point of sleep.
Example
- CPU Usage: Similar to sleeping threads, waiting threads do not consume CPU cycles.
- Memory Footprint: They continue to consume memory by retaining stack, heap, and thread-local storage.
- Synchronization: These threads are often part of a synchronized operation and typically have a more extended impact on scheduling and threading overhead.
Related reading
- How much space and processing will be optimized in Lucene index by storing a field as Byte instead of String for billions of documents
- How much speed is gained with RequireJS/AMD in JS?
- How OVE is equal to Obd In BFS
- How should I store GUID in MySQL tables?
- How MySQL replicate the rows in a table ? and in which order
- How non-blocking API works?
- How should I use torch.compile properly?
- How slow are .NET exceptions?

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
Data Structures & Algorithms practice on Codemia
Step through 300 algorithm problems with animated visualisers that show the data structure changing as the code runs.