Java.lang.Thread.start() 方法
描述
java.lang.Thread.start()方法使这个线程开始执行,Java虚拟机调用这个线程的run方法。结果是两个线程同时运行:当前线程 (从对 start 方法的调用返回)和另一个线程(执行其 run 方法)。
声明
以下是 java.lang.Thread.start() 方法的声明。
public void start()
参数
NA
返回值
此方法不返回任何值。
异常
IllegalThreadStateException − 如果线程已经启动。
示例
下面的例子展示了 java.lang.Thread.start() 方法的使用。
package com.tutorialspoint;
import java.lang.*;
public class ThreadDemo implements Runnable {
Thread t;
ThreadDemo() {
// 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 ThreadDemo();
}
}
让我们编译并运行上面的程序,这将产生下面的结果 −
thread = Thread[Admin Thread,5,main] Calling run() function... Inside run()function

