| Refresh | Home EGTry.com

create a thread java class by implements Runnable interface


RunnableImp.java

/*
 * Copyright@ 2011 www.egtry.com
 */

package egtry.thread;

///create a thread class by implements Runnable
public class RunnableImp implements Runnable {

  public static void main(String[] args) {
	  System.out.println("Main Thread at the beginning: "+Thread.currentThread().getId());
	  RunnableImp runner=new RunnableImp();
	  Thread t1=new Thread(runner);
	  t1.start();
	  System.out.println("Main Thread at the end: "+Thread.currentThread().getId());
  }

  @Override
  public void run() {
	
	System.out.println("Thread started");
	System.out.println("Child Thread: "+Thread.currentThread().getId());
  }
}



Output

Main Thread at the beginning: 1
Main Thread at the end: 1
Thread started
Child Thread: 8