Java: is JVM thread priority changed (implicitly)

When we create new Thread(Runnable target)

, it will have some priority depending on the parent thread. My question is, can the priority be changed by the JVM under any circumstance? I am not using setPriority (int) method.

+3


source to share


3 answers


If you are asking, the thread scheduler to schedule threads according to their priority, the answer is no .

He can choose this (pre-scheduling), but it is platform dependent to decide which scheduling algorithm to use.



Some indications:

+2


source


Not. I won't. Just add under the hoods your OS or system that has a final call on which threads will run on it and therefore its own scheduling algorithm ultimately matters.



However, the JVM presents threads to the OS, and here the priority again plays a role based on the JVM scheduling algorithm, but its OS that decides.

+2


source


I don't see any explicit guarantees for this, but this is not a thing that comes with explicit guarantees.

There is a getter and a setter for the priority, and the implication is that the value won't change unless someone calls the setter again.

But note that this does not mean that no part of the system can call setPriority()

in your "threads", just that Thread

there is no internal trick inside the class itself .

+1


source







All Articles