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 {
/*  w  ww. j a  v a  2 s.  co m*/
  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();
  }

}




















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable