我一次性在主程序中开启了多个线程,比如100个,我怎么判断这100个都执行完成了呢。比如
int i=100;
while(i>0)
 {
 Mythread t=new Mythread();
 t.run();
--i;
}
??????这里有什么办法判断上面100个线程都做完成了吗?是否要在Mythread数据结构里面增加什么参数,没有思路。

解决方案 »

  1.   

    您就加入
    static int k=0;
    while(i>0)
     {
     Mythread t=new Mythread(k);//其中k传入,在类t中执行末尾加入判断k数字
                                       //k达到100就完了呵呵
     t.run();
    --i;
    k++;
    }
    http://my.6cncn.cn
      

  2.   

    http://my.6cncn.cn
    b.join(a)
    b.start();
    是等待一个线程a结束了以后
    b才开始运行的呵呵!
    不能用
      

  3.   

    Mythread ta[]=new Mythread[100];
    int i=100;
    while(i>0)
     {
     Mythread t=new Mythread();
     ta[i];
     t.start();
    }
    for(int i=0;i<100;i++){
     ta[i].join();
    }
      

  4.   

    widowss (widowss)  老兄,你书写的不是启动 100 个线程!!!!!!!!!!!必须使用 Thread.start() 方法!!!!!!使用 thread.join() 等待它执行完成
      

  5.   

    Mythread ta[]=new Mythread[100];
    int i=100;
    while(i>0)
     {
     Mythread t=new Mythread();
     ta[i]=t;///笔误
     t.start();
    }
    for(int i=0;i<100;i++){
     ta[i].join();
    }
      

  6.   

    to:XiXiangHou() 
    start就是run.run就是start
      

  7.   

    to:XiXiangHou() 
    start就是run.run就是start    /**
         * Causes this thread to begin execution; the Java Virtual Machine 
         * calls the <code>run</code> method of this thread. 
         * <p>
         * The result is that two threads are running concurrently: the 
         * current thread (which returns from the call to the 
         * <code>start</code> method) and the other thread (which executes its 
         * <code>run</code> method). 
         *
         * @exception  IllegalThreadStateException  if the thread was already
         *               started.
         * @see        java.lang.Thread#run()
         * @see        java.lang.Thread#stop()
         */
        public synchronized native void start();