cleanup work

This commit is contained in:
eugenp 2014-12-28 14:35:48 +02:00
parent 8396d96a4c
commit 983823dbfa
1 changed files with 16 additions and 0 deletions

View File

@ -84,6 +84,22 @@ public class JavaTimerUnitTest {
Thread.sleep(delay * 3);
}
@Test
public void givenUsingTimer_whenStoppingThread_thenTimerTaskIsCancelled() throws InterruptedException {
final TimerTask task = new TimerTask() {
@Override
public void run() {
System.out.println("Task performed on " + new Date());
// TODO: stop the thread
}
};
final Timer timer = new Timer("Timer");
timer.scheduleAtFixedRate(task, 1000L, 1000L);
Thread.sleep(1000L * 10);
}
@Test
public void givenUsingTimer_whenCancelingTimer_thenCorrect() throws InterruptedException {
final TimerTask task = new TimerTask() {