Tuesday, 29 November 2016

Program to getting the main thread

This is a simple program in which we are getting the reference of currently executing thread object. The currentThread( ) method returns the reference of currently executing thread. The getName( ) returns the thread name.


PROGRAM
class GettingMainThread {

 public static void main (String[] args) {
  Thread thread = Thread.currentThread();
  System.out.println("Main thread is named : "+thread.getName());
 }
}
OUTPUT
C:\>javac GettingMainThread.java
C:\>java GettingMainThread
Main thread is named : main

No comments:

Post a Comment