Java — Thread Priorities | Code Factory

Thread.MIN_PRIORITY
Thread.NORM_PRIORITY
Thread.MAX_PRIORITY
/* Returns this thread's priority. */
public final int getPriority()
/* Changes the priority of this thread. */
public final void setPriority(int newPriority)
t.setPriority(7);   // ✓
t.setPriority(17); // X
package com.example.thread;public class ThreadTest {
public static void main(String... args) {
System.out.println(Thread.currentThread().getPriority());
//Thread.currentThread().setPriority(15); // RE : IllegalArgumentException
Thread.currentThread().setPriority(7);
MyThread t = new MyThread();
System.out.println(t.getPriority());
}
}
class MyThread extends Thread {

}
5
7

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store