2
2
_ Reference_ : https://www.amazon.com/Modern-Java-Action-functional-programming/dp/1617293563
3
3
4
4
# project description
5
- 1 . We could get ask shop for a price of product (id)
5
+ 1 . We could ask shop for a price of product (by id)
6
6
```
7
7
class Shop {
8
8
Price getPrice(int id) {
@@ -23,11 +23,12 @@ _Reference_: https://www.amazon.com/Modern-Java-Action-functional-programming/dp
23
23
}
24
24
}
25
25
```
26
- 1. we want to ask shop for many ids (for example stream of ids)
26
+ 1. we want to ask shop for many ids (for example
27
+ we have a stream of ids)
27
28
28
29
# solution
29
- * naive approach -
30
- * one
30
+ * ** naive approach** - scales badly
31
+ * one product
31
32
```
32
33
var priceFutures = IntStream.range(1, 2)
33
34
.parallel()
@@ -41,7 +42,7 @@ _Reference_: https://www.amazon.com/Modern-Java-Action-functional-programming/dp
41
42
.collect(toList());
42
43
```
43
44
**time: 203 ms**
44
- * four
45
+ * four products
45
46
```
46
47
var priceFutures = IntStream.range(1, 4)
47
48
.parallel()
@@ -55,7 +56,7 @@ _Reference_: https://www.amazon.com/Modern-Java-Action-functional-programming/dp
55
56
.collect(toList());
56
57
```
57
58
**time: 203 ms**
58
- * scales badly
59
+ * many products
59
60
```
60
61
var priceFutures = IntStream.range(1, 30)
61
62
.parallel()
@@ -69,7 +70,7 @@ _Reference_: https://www.amazon.com/Modern-Java-Action-functional-programming/dp
69
70
.collect(toList());
70
71
```
71
72
**time: 2 s**
72
- * dedicated executor - scales perfectly
73
+ * ** dedicated executor** - scales perfectly
73
74
```
74
75
var executor =
75
76
Executors.newFixedThreadPool(Math.min(300, 100),
@@ -99,7 +100,7 @@ number of threads equal to the one returned by
99
100
100
101
So we decide to prepare dedicated executor for
101
102
`CompletableFuture` tasks. How we estimated
102
- the number of possible threads in a pool?
103
+ the number of threads in a fixed pool?
103
104
From the given formula:
104
105
105
106
* `Nthreads = NCPU * UCPU * (1 + W/C)`
0 commit comments