AAA aaa = new AAA();
aaa.start();
不行吗?

解决方案 »

  1.   

    你不知道我的意思,用BBB调用AAA类,作到随时停止和启动!
      

  2.   

    class BBB{
      private AAA aThread;  
      public void setAAA(AAA a){
        this.aThread = a;  
      }
      public void startAAA(){
         aThread.start();
      }
      public void stopAAA(){
        aThread.stopMe();
      }
    }public class AAA extends Thread{
    ......
      boolean flag = false;
      public void run(){
        while(true){
         if(flag){
           break; 
         }
        ......
        }  }
      public void stopMe(){
        flag=true; 
      }
    }
      

  3.   

    class BBB {
      
       AAA aaa = new AAA();
       
       void start() {
          aaa.start();
       }
       void stop () {
          aaa .stop();
       }
    }
    不过不建议使用Thread.stop() ,你还是在AAA的run方法中改一下public class AAA extends Thread{
    ......
      boolean stop;
      public void run(){
        while(!stop){
        ......
        }  }  
    }
    在BBB的stop中, 调用aaa.stop = true;就可以停止了