File tree Expand file tree Collapse file tree 2 files changed +55
-5
lines changed
src/main/java/org/geekbang/time/commonmistakes Expand file tree Collapse file tree 2 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -228,11 +228,29 @@ public void skipLimit() {
228
228
229
229
@ Test
230
230
public void peek () {
231
- orders .stream ()
232
- .filter (order -> order .getTotalPrice () > 40 )
233
- .peek (order -> System .out .println (order .toString ()))
234
- .map (Order ::getCustomerName )
235
- .collect (toList ());
231
+ IntStream .rangeClosed (1 , 10 )
232
+ .peek (i -> {
233
+ System .out .println ("第一次peek" );
234
+ System .out .println (i );
235
+ })
236
+ .filter (i -> i > 5 )
237
+ .peek (i -> {
238
+ System .out .println ("第二次peek" );
239
+ System .out .println (i );
240
+ })
241
+ .filter (i -> i % 2 == 0 )
242
+ .forEach (i -> {
243
+ System .out .println ("最终结果" );
244
+ System .out .println (i );
245
+ });
246
+
247
+ // orders.stream()
248
+ // .filter(order -> order.getTotalPrice() > 40)
249
+ // .peek(order -> System.out.println(order.toString()))
250
+ // .map(Order::getCustomerName)
251
+ // .collect(toList());
252
+
253
+
236
254
}
237
255
238
256
@ Test
Original file line number Diff line number Diff line change
1
+ package org .geekbang .time .commonmistakes .troubleshootingtools .mat ;
2
+
3
+ import lombok .extern .slf4j .Slf4j ;
4
+ import org .springframework .boot .CommandLineRunner ;
5
+ import org .springframework .boot .SpringApplication ;
6
+ import org .springframework .boot .autoconfigure .SpringBootApplication ;
7
+
8
+ import java .util .UUID ;
9
+ import java .util .concurrent .TimeUnit ;
10
+ import java .util .stream .Collectors ;
11
+ import java .util .stream .IntStream ;
12
+
13
+ @ SpringBootApplication
14
+ @ Slf4j
15
+ public class JMapApplication implements CommandLineRunner {
16
+
17
+ //-Xmx512m -Xms512m
18
+ public static void main (String [] args ) {
19
+ SpringApplication .run (JMapApplication .class , args );
20
+ }
21
+
22
+ @ Override
23
+ public void run (String ... args ) throws Exception {
24
+ while (true ) {
25
+ String payload = IntStream .rangeClosed (1 , 1000000 )
26
+ .mapToObj (__ -> "a" )
27
+ .collect (Collectors .joining ("" )) + UUID .randomUUID ().toString ();
28
+ log .debug (payload );
29
+ TimeUnit .MILLISECONDS .sleep (1 );
30
+ }
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments