File tree Expand file tree Collapse file tree 2 files changed +6
-6
lines changed
src/com/winterbe/java8/samples/concurrent Expand file tree Collapse file tree 2 files changed +6
-6
lines changed Original file line number Diff line number Diff line change 1111 */
1212public class Atomic1 {
1313
14- private static final int NUM_INCREMENTS = 10000 ;
14+ private static final int NUM_INCREMENTS = 1000 ;
1515
1616 private static AtomicInteger atomicInt = new AtomicInteger (0 );
1717
Original file line number Diff line number Diff line change 33import java .util .concurrent .ExecutorService ;
44import java .util .concurrent .Executors ;
55import java .util .concurrent .atomic .LongAccumulator ;
6+ import java .util .function .LongBinaryOperator ;
67import java .util .stream .IntStream ;
78
89/**
910 * @author Benjamin Winterberg
1011 */
1112public class LongAccumulator1 {
1213
13- private static final int SIZE = 10 ;
14-
15- private static LongAccumulator accumulator = new LongAccumulator ((x , y ) -> 2 * x + y , 1L );
16-
1714 public static void main (String [] args ) {
1815 testAccumulate ();
1916 }
2017
2118 private static void testAccumulate () {
19+ LongBinaryOperator op = (x , y ) -> 2 * x + y ;
20+ LongAccumulator accumulator = new LongAccumulator (op , 1L );
21+
2222 ExecutorService executor = Executors .newFixedThreadPool (2 );
2323
24- IntStream .range (0 , SIZE )
24+ IntStream .range (0 , 10 )
2525 .forEach (i -> executor .submit (() -> accumulator .accumulate (i )));
2626
2727 ConcurrentUtils .stop (executor );
You can’t perform that action at this time.
0 commit comments