我新建了一个线程组和一个线程,现在我想指定这个线程所在线程组为新线程组。如何做?请大家帮帮我啊

解决方案 »

  1.   

    没有看到过你这个方法,一般是再创建线程的时候就指定group了。呵呵。
    我现在去看看为什么。/
      

  2.   

    恩,ThreadGroup有这个方法
        /**
         * Adds the specified Thread to this group.
         * @param t the Thread to be added
         * @exception IllegalThreadStateException If the Thread group has been destroyed.
         */
        void add(Thread t) {
    synchronized (this) {
        if (destroyed) {
    throw new IllegalThreadStateException();
        }
        if (threads == null) {
    threads = new Thread[4];
        } else if (nthreads == threads.length) {
    Thread newthreads[] = new Thread[nthreads * 2];
    System.arraycopy(threads, 0, newthreads, 0, nthreads);
    threads = newthreads;
        }
        threads[nthreads] = t;     // This is done last so it doesn't matter in case the
        // thread is killed
        nthreads++;
    }
        }
      

  3.   

    新建的线程默认情况下是加如最新创建的线程组中,也可以自己指定线程组,参考具体的API
      

  4.   

    你可以调用
    public Thread(ThreadGroup group,
                  Runnable target)来指定线程组啊