[concurrency-interest] ScheduledFuture and Binary latch

Joe Bowbeer joe.bowbeer at gmail.com
Thu Jun 5 18:51:44 EDT 2008


On Thu, Jun 5, 2008 at 3:02 PM, robert lazarski wrote:
>
> Problem: I want to write a latch, perhaps a semaphore, that skips this
> task if its already running. So I want to acquire some type of lock
> when I start this task, skip the task if its already been started, and
> release the lock when this single task is completed. CountDownLatch
> doesn't seem right for a repeatable task. I've written a few versions
> of BinaryLatch but nothing seems right to me. Any ideas?
>

final AtomicBoolean isRunning = new AtomicBoolean()

if (isRunning.compareAndSet(false, true))
    try {
        // run task
    } finally {
        isRunning.set(false);
    }


More information about the Concurrency-interest mailing list