Java Threads - 1 thread to block another
This is the situation
I have a master controller that spuns 2 listener thread
listener thread A that listens for device A
listener thread B that listens for device B
Upon event received from device A/B, the business classes would be activated accordingly to run the bis logic and stuff
There however, exists this use case
- event received at device A
- listener thread A loads business rules
- part of this business rules involves reading from device B
Now, if i do interact with device B, listener thread B in this case will be activated!. I do not want this. Is there anyway for listener thread A in this case, to block the thread B (even closing the IO for device B) and then proceed to read from device B?
Thanks!
[784 byte] By [
stdouta] at [2007-10-2 22:02:28]

If the thread listening to B is in an IO wait state you may, or may not, be able to interrupt it with an interrupt call to the thread. I think a more viable strategy might be to divert the input from B after the call returns. The problem is, it sounds to me you might have trouble telling an asychronous event from B with a reponse to the new interaction you are trying to initiate with A. It's hard to know with the scant detail you supply.
One strategy might be to have the B listener place items on a blocking queue. The regular events from B would then be handled by a thread separate from the primary B listener thread, so your A process, having sent it's request to the B chanel, could then watch the queue for a reply.