本帖最后由 247033993@qq.co 于 2014-5-25 16:49 编辑
- public class Test_Join {
- /**
- * @param args
- */
- public static void main(String[] args) {
- JoinMethod j=new JoinMethod();
- Thread a=new Thread(j,"线程A");
- Thread b=new Thread(j,"线程B");
- Thread c=new Thread(j,"线程c");
- a.start();
- b.start();
- c.start();
- try {
- Thread.sleep(2000);
- } catch (InterruptedException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
- System.out.println("======================");
- System.out.println(c.isAlive());
- for (int i = 0; i < 10; i++) {
- try {
- c.join();
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
- }
- class JoinMethod implements Runnable{
- public void run(){
- for (int i = 0; i <10; i++) {
- System.out.println(Thread.currentThread().getName());
- }
- }
- }
复制代码
先不说这种极端方法的合理性,线程都运行完了,再使用join,为什么捕获异常这里没有一个关于线程死亡的异常呢? |