import javafx.scene.control.Cell;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.LongAccumulator;

public class Main {

    private static void t1_striped_5() throws InterruptedException {
        int count = 5;
        CountDownLatch countDownLatch = new CountDownLatch(count);

        //param "right" maybe < 0.   I want "right" > 0
        LongAccumulator accumulator = new LongAccumulator( (left, right) -> left + Math.abs(right), 0);

        for (int i=0; i<count; ++i) {
            new Thread(() -> {
                int sign;
                for (int k = 0; k<10000; ++k) {
                    sign = Math.random() > 0.9 ? 1 : -1;

                    //sign < 0, --->    Cell r = new Cell(-1)
                    accumulator.accumulate(sign);
                }

                countDownLatch.countDown();
            }).start();
        }

        countDownLatch.await();

        long result = accumulator.longValue();

        //so result is random (maybe less than expect value 50000)
        System.out.println(result);
    }

    public static void main(String[] args) throws InterruptedException {
	// write your code here
        t1_striped_5();

    }
}
