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

Implement Runnable 

This example shows creating a simple thread by implementing Runnable interface.

File Name  :  
com/bethecoder/tutorials/thread/simple/ImplementRunnable.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.thread.simple;

public class ImplementRunnable implements Runnable {

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

File Name  :  
com/bethecoder/tutorials/thread/simple/ImplementRunnableTest.java 
Author  :  Sudhakar KV
Email  :  kvenkatasudhakar@gmail.com
   
package com.bethecoder.tutorials.thread.simple;

public class ImplementRunnableTest {
  
  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,
Main : 0
ExtendThread : 0
Main : 1
ExtendThread : 1
Main : 2
ExtendThread : 2
Main : 3
ExtendThread : 3
Main : 4
ExtendThread : 4
ExtendThread : 5
Main : 5


                    Print

   



Books Recommendation

 
 
bl  br