Results 1 to 1 of 1
  1. #1
    Java Tip's Avatar
    Java Tip is offline Moderator
    Join Date
    Nov 2007
    Posts
    1,694
    Blog Entries
    430
    Rep Power
    9

    Default Creating a Thread using the Runnable interface

    This example shows how to create a Thread by implementing the Runnable interface.

    Java Code:
    public class RunnableThread implements Runnable {
      private int countDown = 5;
      public String toString() {
        return "#" + Thread.currentThread().getName() +
          ": " + countDown;
      }
      public void run() {
        while(true) {
          System.out.println(this);
          if(--countDown == 0) return;
        }
      }
      public static void main(String[] args) {
        for(int i = 1; i <= 5; i++)
          new Thread(new RunnableThread(), "" + i).start();
        // Output is like SimpleThread.java
      }
    }
    Last edited by Java Tip; 04-09-2008 at 06:34 PM.

Similar Threads

  1. data from the main/GUI thread to another runnin thread...
    By cornercuttin in forum Threads and Synchronization
    Replies: 2
    Last Post: 04-23-2008, 10:30 PM
  2. Error : Runnable did not complete within 10000ms
    By piyushgpt1 in forum Advanced Java
    Replies: 1
    Last Post: 02-05-2008, 07:04 PM
  3. Replies: 0
    Last Post: 01-28-2008, 07:02 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •