Question

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.

Était-ce utile?

La solution

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)

Autres conseils

IMHO, we dont have much control over thread scheduling. Most comtemporary JVMs delegates to native os when it comes to thread scheduling. Some solaris jvms, I heard still uses the concepts of "Green threads". That probably the best shot on what you are trying to achieve. I don't have a solaris machine so I cannot confirm though.

That boils down to two options. 1) Programmatically manipulate the priorities of threads. Threads with higher priorities will be executed first.

or, Modify the os setting, as mentioned in this link http://docs.oracle.com/cd/E24290_01/coh.371/e22838/tune_perftune.htm#CACCHIFA

Can we change the Thread scheduler of JVM.

No, because there isn't one to change. It's in the operating system. Any reference you may encounter to JVM thread scheduling is decades out of date at best and wrong at worst.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top