dacracot
dacracot

Reputation: 22348

Is the an implementation of java.util.concurrent.CountDownLatch which can handle incrementing the initial count upward?

I need a java.lang.Thread to wait for an unpredictable number of predecessor threads to complete as a "choke point" before releasing the spawning of another batch of threads. CountDownLatch seems like it would work if there was a method for countUp as well as countDown.

Is there a implementation like this, or do I need to implement a semaphore singularity myself?

Upvotes: 1

Views: 131

Answers (1)

kostya
kostya

Reputation: 9559

Have a look at java.util.concurrent.Phaser

A reusable synchronization barrier, similar in functionality to CyclicBarrier and CountDownLatch but supporting more flexible usage.

Unlike the case for other barriers, the number of parties registered to synchronize on a phaser may vary over time. Tasks may be registered at any time . . . and optionally deregistered upon any arrival

Upvotes: 2

Related Questions