top examplets

Basic Threads

In real life, you'd put your own code in the run() method.


extending Thread


// ThreadDemo1.java


// This class extends Thread.

class ThreadDemo1 extends Thread
  {


  // Main.  Create one of these and then start it.

  public static void main (String[] args)
    {
    Thread thread = new ThreadDemo1();
    thread.start();
    }


  // This method is run as a separate thread.

  public void run()
    {
    }


  };

See also:


implementing Runnable


// ThreadDemo2.java


// This class implements Runnable.

class ThreadDemo2 implements Runnable
  {


  // Main.  Create a thread and then start it.

  public static void main (String[] args)
    {
    Thread thread = new Thread (new ThreadDemo2() );
    thread.start();
    }


  // This method is run as a separate thread.

  public void run()
    {
    }


  };

See also


Copyright (c) 1997, 1998 by Wayne E. Conrad, All Rights Reserved
Last Updated May 6, 1998
This page has been accidentally visited times since May 1st, 1998.
HTML DTD Validated Best Viewed With Any Browser

This page hosted by Get your own Free Home Page