/** * Copyright (c): Uwe Schmidt, FH Wedel * * You may study, modify and distribute this source code * FOR NON-COMMERCIAL PURPOSES ONLY. * This copyright message has to remain unchanged. * * Note that this document is provided 'as is', * WITHOUT WARRANTY of any kind either expressed or implied. */ public class InterruptedThread extends Thread { int cnt = 0; public void run() { System.out.println("thread: starting"); while ( ! isInterrupted() ) { System.out.println("thread: the " + (++cnt) + ". time"); try { sleep(500); } catch (InterruptedException e) { System.out.println("thread: InterruptedException catched"); interrupt(); } } System.out.println("thread: finished"); } }