| Refresh | Home EGTry.com

create a thread class by extend Thead, and run thead by calling start method


 * Copyright@ 2011 www.egtry.com

package egtry.thread;

///create a thread object by extends Thread
public class ThreadExt extends Thread {

  public static void main(String[] args) {
	  System.out.println("Main Thread at the beginning: "+Thread.currentThread().getId());
	  ThreadExt t1=new ThreadExt();
	  System.out.println("Main Thread at the end: "+Thread.currentThread().getId());
  public void run() {
		System.out.println("Thread started");
		System.out.println("Child Thread: "+Thread.currentThread().getId());


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