public class TestOne implements Runnable{
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
Thread t = new Thread(new TestOne());
t.start();
System.out.print("Started");
t.join();
System.out.print("Completed");
}
public void run(){
for(int i=0; i<4; i++){
System.out.print(i);
}
}
}这个代码的输出为什么是Started0123Completed,t.join();在里面起到了什么作用,一直不太明白join函数的作用是什么?
public static void main(String[] args) throws InterruptedException {
// TODO Auto-generated method stub
Thread t = new Thread(new TestOne());
t.start();
System.out.print("Started");
t.join();
System.out.print("Completed");
}
public void run(){
for(int i=0; i<4; i++){
System.out.print(i);
}
}
}这个代码的输出为什么是Started0123Completed,t.join();在里面起到了什么作用,一直不太明白join函数的作用是什么?
多线程,当然就是异步的了,你多运行几次,每次输出的结果可能都不一样,但是Completed肯定是最后输出
多线程,当然就是异步的了,你多运行几次,每次输出的结果可能都不一样,但是Completed肯定是最后输出多谢
多线程,当然就是异步的了,你多运行几次,每次输出的结果可能都不一样,但是Completed肯定是最后输出
这个例子每次输出都是一样的,因为System.out.print是同步的
多线程,当然就是异步的了,你多运行几次,每次输出的结果可能都不一样,但是Completed肯定是最后输出
这个例子每次输出都是一样的,因为System.out.print是同步的
我擦我看错了,自杀,不要理我