Sum*_*ave 3 java multithreading thread-exceptions
下面的代码运行成功,这是否意味着我们可以启动线程两次?
public class enu extends Thread {
static int count = 0;
public void run(){
System.out.println("running count "+count++);
}
public static void main(String[] args) {
enu obj = new enu();
obj.run();
obj.start();
}
}
Run Code Online (Sandbox Code Playgroud)
输出 - 运行计数0运行计数1
不,当你打电话时,你只开了一个新线程obj.start().obj.run()执行run当前线程中的方法.它不会创建新线程,您可以根据需要多次调用它.
另一方面,obj.start()不可能多次呼叫.
| 归档时间: |
|
| 查看次数: |
64 次 |
| 最近记录: |