public class ThreadDemo {
private static boolean stopRequested;
public static void main(String args[]) throws InterruptedException {
Thread backageThread = new Thread(new Runnable() {
@Override
public void run() {
int i = 0;
while (!stopRequested)
i++;
}
});
backageThread.start();
TimeUnit.SECONDS.sleep(1);
stopRequested = true;
}
}