tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Java > Threading > Basic > Extend Thread

Extend Thread 

This example shows creating a simple thread by extending Thread class.

File Name  :  
com/bethecoder/tutorials/thread/simple/ExtendThread.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.thread.simple;

public class ExtendThread extends Thread {

  public void run() {
    
    for (int i = ; i < 6; i ++ ) {
      System.out.println("ExtendThread : " + i);
      try {
        Thread.sleep(10L);
      catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
  }
}
   

File Name  :  
com/bethecoder/tutorials/thread/simple/ExtendThreadTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.thread.simple;

public class ExtendThreadTest {
  
  public static void main (String [] argsthrows InterruptedException {
    ExtendThread thread = new ExtendThread();
    thread.start();
    
    for (int i = ; i < ; i ++) {
      System.out.println("Main : " + i);
      Thread.sleep(10L);
    }
  }
}
   

It gives the following output,
ExtendThread : 0
Main : 0
Main : 1
ExtendThread : 1
Main : 2
ExtendThread : 2
Main : 3
ExtendThread : 3
ExtendThread : 4
Main : 4
Main : 5
ExtendThread : 5



 
  


  
bl  br