We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8396d96 commit 983823dCopy full SHA for 983823d
core-java/src/test/java/org/baeldung/java/JavaTimerUnitTest.java
@@ -84,6 +84,22 @@ public void run() {
84
Thread.sleep(delay * 3);
85
}
86
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
103
@Test
104
public void givenUsingTimer_whenCancelingTimer_thenCorrect() throws InterruptedException {
105
final TimerTask task = new TimerTask() {
0 commit comments