I have some classes that implement Runnable interface. Each of them is is executed via the separate SingleThreadExecutor. I cannot modify the execution routine, I can just provide different Runnables for it.
I need to make some operations with Runnables depending on other Runnables results. I.e. I want to run some operation inside run() method only in case all other Runnables have reached that point of execution. Or, I want to run some routine inside the run() method only if the number of Runnables that are doing the same is less than 10.
The only solution I see is to make a static variable CountDownLatch and Semaphore to synchronize on.
I implemented this, but for some unknown reasons, starting from some Runnable SingleThreadExecutor is not starting the thread with next Runnable if some Runnables are waiting for Latch or Semaphore. For example 7 Runnables start, others do not.
My question: is my scheme of synchronizing on static Latch or Semaphore a correct one?