<<< Thread interruption - manual checks | Index | Example: Counter class gets interrupted >>> |
import java.util.Scanner; public class Main { public static void main(String[] args) { System.out.println( "Press the Enter key to stop counting:" ); Thread counter = new Thread( new Counter() ); // start the counter thread counter.start(); Scanner sc = new Scanner( System.in ); String str = "start"; // wait for the user to press Enter while ( !str.equals("") ) { str = sc.nextLine(); } // interrupt the counter thread counter.interrupt(); } }//class Main
<<< Thread interruption - manual checks | Index | Example: Counter class gets interrupted >>> |