Skip to content

Commit 983823d

Browse files
author
eugenp
committed
cleanup work
1 parent 8396d96 commit 983823d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

core-java/src/test/java/org/baeldung/java/JavaTimerUnitTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,22 @@ public void run() {
8484
Thread.sleep(delay * 3);
8585
}
8686

87+
@Test
88+
public void givenUsingTimer_whenStoppingThread_thenTimerTaskIsCancelled() throws InterruptedException {
89+
final TimerTask task = new TimerTask() {
90+
@Override
91+
public void run() {
92+
System.out.println("Task performed on " + new Date());
93+
// TODO: stop the thread
94+
}
95+
};
96+
final Timer timer = new Timer("Timer");
97+
98+
timer.scheduleAtFixedRate(task, 1000L, 1000L);
99+
100+
Thread.sleep(1000L * 10);
101+
}
102+
87103
@Test
88104
public void givenUsingTimer_whenCancelingTimer_thenCorrect() throws InterruptedException {
89105
final TimerTask task = new TimerTask() {

0 commit comments

Comments
 (0)