Java Data Type Tutorial - Java Thread.start()








Syntax

Thread.start() has the following syntax.

public void start()

Example

In the following code shows how to use Thread.start() method.

class ThreadDemo extends Thread {
/* ww  w .j  a va  2 s .c  om*/
  public void run() {
    System.out.println("This is run() method");
  }

}

public class Main {

  public static void main(String args[]) {
    Thread currThread = Thread.currentThread();
    // thread created
    Thread t = new Thread(new ThreadDemo(), "java2s.com thread");

    System.out.println("current thread = " + currThread);
    System.out.println("thread created = " + t);
    // this will call run() function
    t.start();
  }

}

The code above generates the following result.