2:47 am - Friday April 19, 2019

Thread Example program for currentThread()

CANDID INDUSTRIAL TRAINING -- CHENNAI
Corporate Training for Experienced Candidate
Struts | Hibernate | Spring | Java / J2EE
SOAP | RestFull | Design Pattern | more...
Ph: +91 72000 69003
137b, 2nd st, shanthi nagar, Chrompet, Chennai -600044
/**
*@author :CandidJava.com
*@descriptions : This program explain the function and the use of Current Thread()
*/
class GetCurrentThread implements Runnable
{
  Thread th;

 public GetCurrentThread(String threadName)
 {
  th= new Thread(this,threadName);
  th.start();
  }

  public void run()
  {
    System.out.println(th.getName()+" is starting.....");
  System.out.println("Current thread name : "+
  Thread.currentThread().getName());
  }
  }
  class main
  {

  public static void main(String args[])
  {
  System.out.println("Current thread name : "+
  Thread.currentThread().getName());
  new GetCurrentThread("1st Thread");
  new GetCurrentThread("2nd Thread");
  }
}

output

Current Thread name is main
1st Thread is starting
Current thread name:1st Thread
2nd thread is starting
Current Thread name:2nd Thread

Filed in: Z-A All Java Codes

Comments are closed.