static boolean stopRequested = false;public static synchronized boolean isStopped() {return stopRequested;}public static synchronized void stopRequested() {StopThread.stopRequested = true;}public static void main(String ar[]) throws InterruptedException {Thread runningThread = new Thread(new Runnable() {@Overridepublic void run() {while (!isStopped()) {System.out.println(stopRequested);}}});runningThread.start();System.out.println("Stop Running Thread");stopRequested();}
Labels
Stop a thread in java
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment