发布网友 发布时间:2022-04-25 12:16
共2个回答
热心网友 时间:2023-09-22 02:30
用ThreadPoolExecutor,其中BlockQueue使用LinkedBlockingQueue(此队列按 FIFO(先进先出)排序元素)。
热心网友 时间:2023-09-22 02:31
Thread t1 = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("t1...");
}
});
Thread t2 = new Thread(new Runnable() {
@Override
public void run() {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("t2...");
}
});
Thread t3 = new Thread(new Runnable() {
@Override
public void run() {
System.out.println("t3...");
}
});
t1.start();
t1.join();
t2.start();
t2.join();
t3.start();