Can we change the Thread scheduler of JVM. Suppose my JVM is working on preemptive scheduling of threads than can i change it to my custom thread scheduling algorithm or does JVM provide choices for scheduler.
A thread scheduler in java is the part of the JVM that decides which thread should run and which should wait. The thread scheduler always chooses a thread to run only if it is in the RUNNABLE state. But there is no guarantee which thread will be chosen to run if you have multiple threads in RUNNABLE state.
The Java runtime environment supports a very simple, deterministic scheduling algorithm called fixed-priority scheduling. This algorithm schedules threads on the basis of their priority relative to other Runnable threads. When a thread is created, it inherits its priority from the thread that created it.
A component of Java that decides which thread to run or execute and which thread to wait is called a thread scheduler in Java. In Java, a thread is only chosen by a thread scheduler if it is in the runnable state.
Scheduling of user level threads (ULT) to kernel level threads (KLT) via lightweight process (LWP) by the application developer.
In general the JVM doesn't do any scheduling. That is the task of the OS. Linux for example has configurable scheduling options, and if you want to add a new scheduling strategy, you can change the kernel.
However, depending on why you want to do this, you can solve the problem another way such as using a custom Executor, or a Reactor style framework, or effectively disabling scheduling for a CPU and doing all the work in Java yourself. (Not a trivial topic, rarely very useful)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With