Point to remember in case of Thread priorities
- Valid range of Java Thread priorities is from 1 to 10
- 1 is the MIN priority (Thread.MIN_PRIORITY)
- 10 is the MAX priority (Thread.MAX_PRIORITY)
- 5 is the NORMAL priority (Thread.NORM_PRIORITY)
- The default priority of main thread is 5 for all other threads the default priority will be inherited from parent thread to the child thread.
public final int getPriority(); public final void setPriority(int p); //allowed values from 1 to 10
public class ThreadNameDemo {
public static void main(String[] args) {
Thread.currentThread().setPriority(Thread.MIN_PRIORITY);
Thread t = new Thread(new TempThread());
t.setPriority(Thread.MAX_PRIORITY);
t.start();
IntStream.rangeClosed(1,10).forEach(x -> System.out.println(Thread.currentThread().getName()+" "+x));
}
}
class TempThread implements Runnable{
@Override
public void run() {
IntStream.rangeClosed(1,10).forEach(x -> System.out.println(Thread.currentThread().getName()+" "+x));
}
}