2 Replies Latest reply on May 7, 2008 2:46 AM by Tim Fox

    Elegant way of Variable Latch for the waits on AIO?

    Clebert Suconic Master

      Anyone knows a class that would act like a VariableCountDown? i.e. you have countUp and countDown?

      I need to find an elegant way to implement this:

      Say, you have messages being added to a transaction. Of course you will never know of hand how many messages are added to the transaction until you have called commit.

      When the commit is called you need to wait the callback for every message being persisted before leaving the method, so at that point I would call await for every message that was added to the Latch.

      Semaphores won't work as we don't know the number of requests of hand. So I looked into AbstractQueuedSycnrhonizer.. but the implementation is so trivial that I ended up copying CountDownLatch as VariableCountLatch. The result worked the way I expected, but I don't want to reinvent the wheel if there is some class out there doing what I needed.

      (Of course I googled it.. but I didn't find anything like that)

      I could just write a wait/notify object over simple synchronization, but I was looking for a java.util.concurrent style of implementation for this. But if we find out there is no good reason for it I can just implement the synchronize, counter--, counter++, wait and notify approach. (i.e. the traditional way)