The main Thread

When a Java program starts up, one thread begins running immediately. This is usually called the main thread of your program, because it is the one that is executed when your program begins. The main thread is important for two reasons:
• It is the thread from which other “child” threads will be Call forth.
• Often, it must be the last thread to finish execution because it performs various shutdown actions.
Example is as follows :

public class Example1 {
	public static void main(String[] args) {
		// retreive current main thread and copy it to object t of thread type 
		Thread t = Thread.currentThread();
		t.setName("ABC"); // set name of the thread
		System.out.println("Current Thread" + t);
		// get name only of current thread directly 
		System.out.println("default Thread " + Thread.currentThread().getName());

You may also like...