找它出来,然后
Thread.setName(ThreadName)
public Thread findThread(String target) 
      {
         int SAFETY_MARGIN = 10;
         // Find master ThreadGroup which all others descend
         ThreadGroup rootGroup = Thread.currentThread().getThreadGroup();
         while(rootGroup.getParent() != null) 
         {
            rootGroup = rootGroup.getParent();
         }
         Thread threadList[] = new Thread[rootGroup.activeGroupCount() + SAFETY_MARGIN];
         int count = rootGroup.enumerate(threadList);
         Thread aThread;
         for(int i = 0; i < count; i ++ ) 
         {
            aThread = threadList[i];
            if(aThread == null) 
               continue;
            if(aThread.getName().equals(target)) 
            {
               return aThread;
            }
         }
         return null;
      }
---------------
[email protected]

解决方案 »

  1.   

    Thread.stop()
    杀死当前Thread!不过建议不要使用!
      

  2.   

    Thread.setName(ThreadName)这样就能杀死线程吗?
      

  3.   

    stop()方法从技术上来讲,可以终止一个线程,但是很容易造成对象的不连续,你不知道什么时候终止它是安全的……
    建议用core java作者所说,定义一个变量来表示这个线程是否有终止的要,让线程定期检测这个变量。
    比如:
    public class MyThread extends Thread {
      public void run() {
        while(!stopRequested && more work to do) {
          do more work
        }
      }
      public void requestStop() {
        stopRequested = true;
      }
      private boolean stopRequested;
      
    }
      

  4.   

    or like this:public void run(){
      while(live){
        //do your work
      }
    }when you want to kill your thread safely
    turn the live = false