Thread start() Method in Java Example
Chapter:
Thread
Last Updated:
21-07-2016 11:00:57 UTC
Program:
/* ............... START ............... */
import java.lang.*;
public class JavaThreadStartExample implements Runnable {
Thread t;
JavaThreadStartExample() {
// thread created
t = new Thread(this, "Admin Thread");
// prints thread created
System.out.println("thread = " + t);
// this will call run() function
System.out.println("Calling run() function... ");
t.start();
}
public void run() {
System.out.println("Inside run()function");
}
public static void main(String args[]) {
new JavaThreadStartExample();
}
}
/* ............... END ............... */
Output
thread = Thread[Admin Thread,5,main]
Calling run() function...
Inside run()function
Notes:
-
The java.lang.Thread.start() method causes this thread to begin execution, the Java Virtual Machine calls the run method of this thread.
- Syntax : public void start().
Tags
Thread start() Method, Java