package com.moto.amtg.oos.instant;import java.io.*;public class AThread extends Thread {    boolean stopFlag;
    
    public AThread() {
    }
    
    public void run() {
        int i = 0;
        while (!stopFlag) {
            i++;
            System.out.println(i);
            try {
                BufferedReader br = GetBufferedReader();
                String line = null;
                while ((line = br.readLine()) != null) {
                    System.out.println("Athread 's run method ");
                    System.out.println(line);
                }
            } catch (IOException ioe) {
                System.out.println(ioe);
            }
        }
    }
    public void stopCurrentThread() {
        stopFlag = true;
    }    private static BufferedReader GetBufferedReader() {
        String strFile =
            System.getProperty("user.home")
                + File.separatorChar
                + "data"
                + File.separatorChar
                + "fm"
                + File.separatorChar
                + "ev20040616.log";
        System.out.println(strFile);
        BufferedReader br = null;
        try {
            FileReader fr = new FileReader(strFile);
            br = new BufferedReader(fr);
        } catch (IOException ioe) {
            System.out.println(ioe);
        }
        return br;
    }
}

解决方案 »

  1.   

    public void stopCurrentThread() {
        stopFlag = true;
    }必须要写成public sychronized void stopCurrentThread() {
        stopFlag = true;
    }还有boolean stopFlag;
    写成
    volatile boolean stopFlag;
      

  2.   

    yield是使线称暂时让出执行时间,destroy和terminate不够安全
      

  3.   

    楼上的,说什么呢?
    interrupt是让阻塞状态的线程恢复执行,不要误人子弟好不好
      

  4.   

    interrupt()好像是让正在运行的线程结束,若还想运行就得重新启动线程。
      

  5.   

    2种方法
    stop()终止线程
    另一种是run()完后自动终止线程,就是接受ThreadDeath异常