Java: make sure the thread never switches to context

Among about 150 threads on 20 main machines. I want a particular thread to never switch to context. I'm not sure if setting the priority of the MAX_PRIORITY stream will do this or not? Also, if we set the priority to max, is it necessary for the OS to execute the instruction (if I run in sudo mode)?

+4
source share
3 answers

You cannot completely disable thread switching, but by setting the priority of the thread MAX_PRIORITY, you tell the OS thread scheduler (if it supports the priority scheduling policy) to supplant the thread with the lower priority if the higher priority is ready to go.

References

java.lang.Thread Javadoc

Each thread has priority. Threads with a higher priority are executed instead of threads with a lower priority.

https://docs.oracle.com/javase/8/docs/api/java/lang/Thread.html

Linux kernel manager APIs manual page

In priority:

        sched_priority. ,         ,                .

:

:         ,                .

http://man7.org/linux/man-pages/man7/sched.7.html

+4

MAX_PRIORITY ?

. , , .

+2

.

, 150 .


My favorite Katie Sierra :

In JAVA, when it comes to threads, very little is guaranteed

http://albertomorales.eu/in-java-when-it-comes-to-threads-very-little-is-guaranteed/

+2
source

All Articles