package lixi;
public class Num implements Runnable {
@Override
public void run() {
// TODO Auto-generated method stub
for (int i = 0; i <=12; i++) {
try {
Thread.sleep(400);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("危机时刻:"+i+"号车出发!");
}
}
}
package lixi;
public class Jointhread {
public static void main(String[] args) {
// TODO Auto-generated method stub
Thread thread=new Thread(new Num());
thread.start();
for (int i = 0; i <=12; i++) {
try {
thread.sleep(400);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("正常时刻:"+i+"号车出发!");
try {
thread.join(100);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
线程插队
最新推荐文章于 2024-01-15 13:48:38 发布