简体   繁体   中英

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?

你有没有尝试过

Thread.currentThread().setPriority();

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM