Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we change the JVM Thread Scheduler?

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.

like image 975
nikhilgupta86 Avatar asked May 01 '14 07:05

nikhilgupta86


People also ask

Is thread scheduler part of JVM?

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.

Can Java programs control thread scheduling?

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.

What is Java thread scheduler?

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.

What are the two types of thread scheduling?

Scheduling of user level threads (ULT) to kernel level threads (KLT) via lightweight process (LWP) by the application developer.


1 Answers

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)

like image 58
Peter Lawrey Avatar answered Sep 28 '22 01:09

Peter Lawrey