Thread Scheduler In Java
Thread scheduler
In Java, the thread scheduler is the part of the JVM, which decides which thread should run.
There is no assurance that which runnable thread will be chosen to run by the scheduler. Any thread in the runnable state can be chosen by the scheduler to be the one and only running thread and if a thread is not in a runnable state then, it cannot be chosen to be the current running thread. Some method that can influence the scheduler to some extent and we can’t control the behavior of the thread scheduler. Only one thread at a time can run in a single process in Java.
The thread scheduler generally uses preemptive scheduling or time slicing scheduling to schedule the threads in Java.
Difference between Preemptive Scheduling and Time Slicing
Under the preemptive scheduling, the highest priority task performs until it enters the waiting or a dead state or a higher priority task comes into an existence.
Under the time slicing, a task performs for a predefined a slice of time and then reenters the pool of ready tasks. The thread scheduler then decides which task should execute next, based on the priority and other factors.
Summary
Thus, we learnt, Java thread scheduler is the part of the JVM, which decides which thread should run and also learnt the difference between Preemptive Scheduling and Time Slicing in Java.