I'm trying to make certain threads that call a function with the same parameter block until the function returns a 0. Each thread decrements a counter and then check if it's a 0. How would i go on about doing that?
I've tried looking into wait/notifyAll but I'm not sure how to make it work properly. I cant figure out how to notify only specific threads that are waiting on the same parameter, especially if I have 2 sets of threads waiting on two different counters for their parameters.
I'm using a hashmap with a ReentrantReadWriteLock that pairs the parameter with its counter.
count.decreaseCount(s);
while (count.getCount(s) != 0) {
try {
Thread.currentThread().wait();
} catch (InterruptedException e) {
System.out.println("Thread " + threadNo + "is waiting.");
Thread.currentThread().interrupt();
}
}