Understanding phaser in java with an example

前端 未结 3 642
Happy的楠姐
Happy的楠姐 2021-01-06 11:55

I am trying to understand Phaser in java. I wrote an example which is stuck at advance waiting for other parties to arrive.

As far as I understand, phaser is used as

3条回答
  •  感情败类
    2021-01-06 12:32

    You initialize your Phaser with a value of 1:

    Phaser phaser = new Phaser(1);
    

    This means that your main thread is one of the threads you are waiting for, but it never calls arrive().

    As the number of your threads is fixed, you should initialize the Phaser with the thread number, and remove the register() calls.

提交回复
热议问题