Java Program to Demonstrate methods of Thread class

Write a Java program to demonstrate methods of Thread class.



Source Code
public class ThreadMethodsDemo {

	public static void main(String[] args) {
		
		System.out.println("Thread Minimum Prority : "+Thread.MIN_PRIORITY);
		System.out.println("Thread Normal Prority : "+Thread.NORM_PRIORITY);
		System.out.println("Thread Maximum Prority : "+Thread.MAX_PRIORITY);
		Thread t = Thread.currentThread();
		System.out.println("Current Thread details : "+t.currentThread());
		t.setName("Main Thread");
		System.out.println("After changing name of main thread : "+t.currentThread());
		System.out.println("Thread ID : "+t.getId());
		System.out.println("Thread Name : "+t.getName());
		System.out.println("Thread Priority : "+t.getPriority());
		System.out.println("Thread State : "+t.getState());
		System.out.println("Thread Group : "+t.getThreadGroup());
		System.out.println("Is Daemon Thread  : "+t.isDaemon());
		t.setPriority(7);	
		// If priority greater than 10 or less than 1 then IllugalArgumentException is thrown.
		System.out.println("After changing priority it becomes : "+t.getPriority());
	}
}
Output
Thread Minimum Prority : 1
Thread Normal Prority : 5
Thread Maximum Prority : 10
Current Thread details : Thread[main,5,main]
After changing name of main thread : Thread[Main Thread,5,main]
Thread ID : 1
Thread Name : Main Thread
Thread Priority : 5
Thread State : RUNNABLE
Thread Group : java.lang.ThreadGroup[name=main,maxpri=10]
Is Daemon Thread  : false
After changing priority it becomes : 7





"Coding Hub - Learn to code" app now available on Google Play Store