forked from examplehub/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSleepExampleTest.java
More file actions
28 lines (25 loc) · 798 Bytes
/
SleepExampleTest.java
File metadata and controls
28 lines (25 loc) · 798 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
package com.examplehub.basics.thread;
import static org.junit.jupiter.api.Assertions.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.jupiter.api.Test;
class SleepExampleTest {
@Test
void testClockMonitor() throws InterruptedException {
new Thread(
() -> {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
while (true) {
Date date = new Date();
System.out.println(sdf.format(date));
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
})
.start();
Thread.sleep(1000); // set bigger argument to see effect
}
}