-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBestPriceFinder.java
More file actions
34 lines (29 loc) · 1.24 KB
/
BestPriceFinder.java
File metadata and controls
34 lines (29 loc) · 1.24 KB
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
package java;
import java.time.Duration;
import java.time.LocalTime;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
public class BestPriceFinder {
public static void main(String[] args) {
var start = LocalTime.now();
var service = new FlightService();
var futures = service.getQuotes()
.map(future -> future.thenAccept(System.out :: println))
.collect(Collectors.toList());
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0]))
.thenRun(() ->{
var end = LocalTime.now();
Duration duration = Duration.between(start, end);
System.out.println("Retrived all quotes in : " +
duration.toMillis() + " msec.");
});
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
e.printStackTrace();
}
// var service = new FlightService();
// service.getQuote("site1")
// .thenAccept(System.out::println);
}
}