1、使用join
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();
2、如在线程池中
用ThreadPoolExecutor,其中BlockQueue使用LinkedBlockingQueue(此队列按 FIFO(先进先出)排序元素)