File tree 2 files changed +6
-6
lines changed
src/com/winterbe/java8/samples/concurrent
2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 11
11
*/
12
12
public class Atomic1 {
13
13
14
- private static final int NUM_INCREMENTS = 10000 ;
14
+ private static final int NUM_INCREMENTS = 1000 ;
15
15
16
16
private static AtomicInteger atomicInt = new AtomicInteger (0 );
17
17
Original file line number Diff line number Diff line change 3
3
import java .util .concurrent .ExecutorService ;
4
4
import java .util .concurrent .Executors ;
5
5
import java .util .concurrent .atomic .LongAccumulator ;
6
+ import java .util .function .LongBinaryOperator ;
6
7
import java .util .stream .IntStream ;
7
8
8
9
/**
9
10
* @author Benjamin Winterberg
10
11
*/
11
12
public class LongAccumulator1 {
12
13
13
- private static final int SIZE = 10 ;
14
-
15
- private static LongAccumulator accumulator = new LongAccumulator ((x , y ) -> 2 * x + y , 1L );
16
-
17
14
public static void main (String [] args ) {
18
15
testAccumulate ();
19
16
}
20
17
21
18
private static void testAccumulate () {
19
+ LongBinaryOperator op = (x , y ) -> 2 * x + y ;
20
+ LongAccumulator accumulator = new LongAccumulator (op , 1L );
21
+
22
22
ExecutorService executor = Executors .newFixedThreadPool (2 );
23
23
24
- IntStream .range (0 , SIZE )
24
+ IntStream .range (0 , 10 )
25
25
.forEach (i -> executor .submit (() -> accumulator .accumulate (i )));
26
26
27
27
ConcurrentUtils .stop (executor );
You can’t perform that action at this time.
0 commit comments