cleanup work
This commit is contained in:
parent
8396d96a4c
commit
983823dbfa
@ -84,6 +84,22 @@ public class JavaTimerUnitTest {
|
|||||||
Thread.sleep(delay * 3);
|
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
|
@Test
|
||||||
public void givenUsingTimer_whenCancelingTimer_thenCorrect() throws InterruptedException {
|
public void givenUsingTimer_whenCancelingTimer_thenCorrect() throws InterruptedException {
|
||||||
final TimerTask task = new TimerTask() {
|
final TimerTask task = new TimerTask() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user