GuruKulki
GuruKulki

Reputation: 26418

Is it possible to set the priority for the main thread?

As we know that even main is also a thread. So just for the curiosity, is it possible to set the priority for the main thread?

Upvotes: 5

Views: 2346

Answers (3)

Tom Hawtin - tackline
Tom Hawtin - tackline

Reputation: 147164

IIRC, generally setting the priority of a running thread will have no effect. An old trick was to always kick off another thread and abandon main. Indeed this is what the Sun/Oracle JVM now does on Linux in order to change the stack size.

Setting the priority of a thread is typically misguided. Many JRE versions will ignore it altogether.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533530

Its worth noting that this is just a hint to the OS and unless you are administrator or root it might not do anything. Even then it may not help very much. setPriority() is harmless AFAIK.

Upvotes: 0

Codemwnci
Codemwnci

Reputation: 54884

Have you tried

Thread.currentThread().setPriority();

Upvotes: 10

Related Questions