java.lang.Thread.run()%uA0方法被调用时,如果该线程是使用独立Runnable运行对象构造,否则此方法不执行任何操作并返回。
声明
以下是java.lang.Thread.run()方法的声明
public void run()
参数
-
NA
返回值
此方法不返回任何值。
异常
-
NA
例子
下面的例子显示java.lang.Thread.run()方法的使用。
package com.yiibai 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 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] Inside run()function