@@ -15,14 +15,12 @@ public class CyclicBarrierDemo {
1515 private int NUM_PARTIAL_RESULTS ;
1616 private int NUM_WORKERS ;
1717
18-
1918 private void runSimulation (int numWorkers , int numberOfPartialResults ) {
2019 NUM_PARTIAL_RESULTS = numberOfPartialResults ;
2120 NUM_WORKERS = numWorkers ;
2221
2322 cyclicBarrier = new CyclicBarrier (NUM_WORKERS , new AggregatorThread ());
24- System .out .println ("Spawning " + NUM_WORKERS + " worker threads to compute "
25- + NUM_PARTIAL_RESULTS + " partial results each" );
23+ System .out .println ("Spawning " + NUM_WORKERS + " worker threads to compute " + NUM_PARTIAL_RESULTS + " partial results each" );
2624 for (int i = 0 ; i < NUM_WORKERS ; i ++) {
2725 Thread worker = new Thread (new NumberCruncherThread ());
2826 worker .setName ("Thread " + i );
@@ -38,8 +36,7 @@ public void run() {
3836 List <Integer > partialResult = new ArrayList <>();
3937 for (int i = 0 ; i < NUM_PARTIAL_RESULTS ; i ++) {
4038 Integer num = random .nextInt (10 );
41- System .out .println (thisThreadName
42- + ": Crunching some numbers! Final result - " + num );
39+ System .out .println (thisThreadName + ": Crunching some numbers! Final result - " + num );
4340 partialResult .add (num );
4441 }
4542 partialResults .add (partialResult );
@@ -57,13 +54,12 @@ class AggregatorThread implements Runnable {
5754 @ Override
5855 public void run () {
5956 String thisThreadName = Thread .currentThread ().getName ();
60- System .out .println (thisThreadName + ": Computing final sum of " + NUM_WORKERS
61- + " workers, having " + NUM_PARTIAL_RESULTS + " results each." );
57+ System .out .println (thisThreadName + ": Computing final sum of " + NUM_WORKERS + " workers, having " + NUM_PARTIAL_RESULTS + " results each." );
6258 int sum = 0 ;
6359 for (List <Integer > threadResult : partialResults ) {
6460 System .out .print ("Adding " );
6561 for (Integer partialResult : threadResult ) {
66- System .out .print (partialResult + " " );
62+ System .out .print (partialResult + " " );
6763 sum += partialResult ;
6864 }
6965 System .out .println ();
0 commit comments