一、方法v介绍
public final void join() 插入线程)(插队线程)
二、代码示例
S4.java
/*
* Copyright (c) 2020, 2023, webrx.cn All rights reserved.
*
*/
package huang6;
public class S4 extends Thread {
@Override
public void run() {
for (int i = 0; i < 10; i++) {
System.out.println(getName() + "@" + i);
}
}
}
测试类
package huang6;
public class S4Text {
public static void main(String[] args) throws InterruptedException {
/*
public final void join() 插入线程)(插队线程)
*/
S4 s = new S4();
s.setName("土豆");
s.start();
s.join();//表示把s这个线程插入到当前线程之前
//执行在main线程当中的
for (int i = 0; i < 10; i++) {
System.out.println("main线程" + i);
}
}
}
三、运行结果展示