[concurrency-interest] Phaser question

Joe Bowbeer joe.bowbeer at gmail.com
Fri Sep 16 02:58:36 EDT 2011


I suggest not advancing the phaser until the associated JavaFX task has
completed.  Otherwise, the phaser will stop too soon.

Looking at your sample code, where most of the work happens in JavaFX-land,
I'm wondering if the JavaFX animation timeline support might be a better
match for this than a phaser running in a background thread.

Joe

On Thu, Sep 15, 2011 at 11:08 PM, Mohan Radhakrishnan wrote:

>  Hi,****
>
>        My code using the Phaser works the first time. I think here when the
> onAdvance method is overridden (  return phase >= 2 || registeredParties ==
> 0; )  I see log messages showing that the Phase is advancing****
>
> but I suspect that since the Platform.runLater is a separate thread it does
> not execute the task the second and third time.****
>
> ** **
>
> Even though this is not strictly Phaser code only I am trying to understand
> if any thread co-ordination is required here.****
>
> ** **
>
> Thanks,****
>
> Mohan****
>
> ** **
>
> ** **
>
>         List<Runnable> tasks = new ArrayList<Runnable>();****
>
>         Runnable tsk = new Runnable(){****
>
> ** **
>
>                         @Override****
>
>                         public void run() {****
>
>                             Platform.runLater(new Runnable() {****
>
>                                 public void run() {****
>
>                                     //JavaFX animate works fine the first
> time but does not iterate.****
>
>                                 }****
>
>                             });****
>
>                         }****
>
>                     };****
>
>         tasks.add( tsk );****
>
> ** **
>
>         phaser.register();****
>
>         for ( final Runnable task : tasks ) {****
>
>           phaser.register();****
>
>           new Thread() {****
>
>             public void run() {****
>
>                 try {****
>
>                     sleep(1500);****
>
>                 } catch (InterruptedException e) {****
>
>                     //Print info.                }****
>
>                 do {****
>
>                     task.run();****
>
>                     phaser.arriveAndAwaitAdvance(); //Finish phase****
>
>                 } while (!phaser.isTerminated());****
>
>             }****
>
>           }.start();****
>
>         }
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20110915/f12142fc/attachment-0001.html>


More information about the Concurrency-interest mailing list