-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApplication.java
72 lines (63 loc) · 1.59 KB
/
Application.java
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package software.xdev;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.stream.IntStream;
import software.xdev.time.HierarchicalLoggingStopWatch;
import software.xdev.time.HierarchicalStopWatch;
public final class Application
{
@SuppressWarnings("java:S106")
public static void main(final String[] args)
{
try(final HierarchicalStopWatch dummySw = HierarchicalLoggingStopWatch.createStarted(
"Run dummy",
System.out::println, // Could also be LOGGER::debug
true)) // Could also be LOGGER.isDebugEnabled()
{
final List<CompletableFuture<Void>> completableFutures;
try(final HierarchicalStopWatch ignored = dummySw.nested("Launch tasks"))
{
completableFutures = IntStream.of(1, 2, 3)
.mapToObj(i -> CompletableFuture.runAsync(() -> {
try(final var processSw = dummySw.nested("Process " + i, true))
{
try(final var ignore = processSw.nested("Fetch"))
{
sleep(5);
}
try(final var ignore = processSw.nested("Process"))
{
sleep(i * 5);
}
if(i % 2 == 0)
{
try(final var ignore = processSw.nested("Finalize"))
{
sleep(5);
}
}
}
}))
.toList();
}
try(final HierarchicalStopWatch ignore = dummySw.nested("Wait for tasks"))
{
completableFutures.forEach(CompletableFuture::join);
}
}
}
private static void sleep(final int ms)
{
try
{
Thread.sleep(ms);
}
catch(final InterruptedException iex)
{
Thread.currentThread().interrupt();
}
}
private Application()
{
}
}