Monu:
If i understand you correctly, i am using different monitors for wait and notify and so there is no coherency in signaling.
Bang on! You got it rite
Monu:
I am thinking of creating a static object in TheSignaler class(so that it is shared amongst thread instances) and then, using its monitor, call wait() and notify(). what say?
Yeah you can do that. Infact you can use ".class" variable for synchronization. In fact you can make your methods static synchronized (there is hardly any instance level state that you store).
Just a point, the operation "++" is not thread-safe per se. It may so happen that the value of the variable changes between (i + 1) and assigning to i. So, its better to use AtomicIntegers (or cousins thereof) for such counters.
Monu:
Also, the condition around wait() and notify() concerns a static variable which can be altered anywhere in the program. Can this cause any problems?
I think you want the variable to be shared for all instances, rite? So you got to make it static. There is no problem in referring to a static variable in your guard condition.
However, the comment that i have made above is something that
you should incorporate.
BTW, what you are trying to do here is very close to what a
Semaphore offers.
You may want to use it or see the implementation to get hints.