Java — Thread Priorities | Code Factory

Index Page : Link

Donate : Link

WordPress Blog : Link

  • Every Thread in Java has some priority. It may be default priority generated by JVM or customized priority provided by programmer.
  • Thread schedular will use priorities while allocating processor. The thread which is having highest priority will get chance first.
/* 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
  • The default priority only for the main thread is 5. But for all remaining threads default priority will be ingerited from parent to child. That is whatever priority thread has the same priority be there for the child thread.
package com.example.thread;public class ThreadTest {
public static void main(String... args) {
//Thread.currentThread().setPriority(15); // RE : IllegalArgumentException
MyThread t = new MyThread();
class MyThread extends Thread {


Output :




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