Skip to Content

Get Current Thread Example

  1. /*
  2.         Get Current Thread Example
  3.         This Java example shows how to get reference of current thread using
  4.         currentThread method of Java Thread class.
  5. */
  6.  
  7. public class GetCurrentThreadExample {
  8.  
  9.         public static void main(String[] args) {
  10.                
  11.                 /*
  12.                  * To get the reference of currently running thread, use
  13.                  * Thread currentThread() method of Thread class.
  14.                  *
  15.                  * This is a static method.
  16.                  */
  17.                
  18.                 Thread currentThread = Thread.currentThread();
  19.                 System.out.println(currentThread);
  20.                
  21.         }
  22. }
  23.  
  24. /*
  25. Output of the example would be
  26. Thread[main,5,main]
  27. */