It is the entry point from where the execution begins. Every
Java program contains at least one thread which is called the main thread. It
is the entry point from where the execution begins and from the main thread, we
can start other threads. By default there is a main thread existing in every
Java program.
Listing 1
class threadDemo
{
public static void main(String a[])
{
Thread t = Thread.currentThread();
System.out.println("Current Thread: " + t);
t.setName("Demo");
System.out.println("After changing the name, the thread is " + t);
for (int i = 5; i > 0; i--)
{
System.out.println("Current Thread: " + i);
t.sleep(1000);
}
}
}
While doing a multithreading program, the main thread should
terminate only after all the other threads get terminated.