public class StopThreadCorrect extends Thread {
    private static boolean stopRequested;
    private static synchronized void setStop() {
        stopRequested = true;
    }
    private static synchronized boolean getStop() {
        return stopRequested;
    }     
    public void run() {
        int i = 0;
        while (!getStop()) i++;
    }
    public static void main(String[] args) {
        Thread background = new StopThreadCorrect();
        background.start();
        try {Thread.sleep(5);}
        catch (InterruptedException e) {};
        setStop();
    }
}
