Thread Scheduler in Java

Thread scheduler in Java is the component of JVM that determines the execution order of multiple threads on a single processor (CPU). It decides the order in which threads should run. This process is called thread scheduling in Java.

When a system with a single processor executes a program having multiple threads, CPU executes only a single thread at a particular time.

Other threads in the program wait in runnable state for getting the chance of execution on CPU because at a time only one thread can get the chance to access the CPU.

The thread scheduler selects a thread for execution from runnable state. But there is no guarantee that which thread from runnable pool will be selected next to run by the thread scheduler.

Java runtime system mainly uses one of the following two strategies:

  1. Preemptive scheduling
  2. Time-sliced scheduling

Preemptive Scheduling


This scheduling is based on priority. Therefore, this scheduling is known as priority-based scheduling. In the priority-based scheduling algorithm, Thread scheduler uses the priority to decide which thread should be run.
[blocksy-content-block id=”12371″]
If a thread with a higher priority exists in runnable state (ready state), it will be scheduled to run immediately.

In case more than two threads have the same priority, then CPU allocates time slots for thread execution on the basis of first-come, first-serve manner.

Time-Sliced Scheduling


The process of allocating time to threads is known as time slicing in Java. Time-slicing is based on non-priority scheduling. Under this scheduling, every running thread is executed for a fixed time period.

A currently running thread goes to the runnable state when its time slice is elapsed and another thread gets time slots by CPU for execution.

With time-slicing, threads having lower priorities or higher priorities gets the same time slots for execution.


In this tutorial, we explained all the basic points of time slicing and thread scheduler in Java. We hope that you will have understood this simple topic. In the next, we will learn thread priority in Java through various examples.
Thanks for reading!!!

DEEPAK GUPTA

DEEPAK GUPTA

Deepak Gupta is the Founder of Scientech Easy, a Full Stack Developer, and a passionate coding educator with 8+ years of professional experience in Java, Python, web development, and core computer science subjects. With strong expertise in full-stack development, he provides hands-on training in programming languages and in-demand technologies at the Scientech Easy Institute, Dhanbad.

He regularly publishes in-depth tutorials, practical coding examples, and high-quality learning resources for both beginners and working professionals. Every article is carefully researched, technically reviewed, and regularly updated to ensure accuracy, clarity, and real-world relevance, helping learners build job-ready skills with confidence.