java - Pausing a thread from another one: how to or alternatives -


i'm facing problem. have java client-server application manages restaurant; need use keyboard input , output in order manage it. waiter class has 2 threads: 1 reads orders input, , 1 continuatively listening (using multicast) ready dish needs delivered table.
considering meant done keyboard, "ordering" thread writes standard output "do wanna make order? [y/n]" , waits answer, while "delivery" thread listens delivered.
if waiter chooses order something, second thread doesn't show until order finished (done using status boolean); if waiter free (which means, showing hint: "do wanna order?") , ready dish arrives see on standard input "there delivered. wanna deliver it? [y/n]" , wait answer.
problem that, whatever chooses, don't have control on thread read answer: did mean deliver or order?
i've tried many possibilities, not working:
- closing ordering scanner input, can't close;
- pausing first thread other one, can't in java;
- synchronizing everything, not working because threads meant work together, not 1 @ time;
- use semaphores/status boolean, in case need modify "ordering" part, including infinite loop checks semaphores (i can't use acquire or release without stopping everything).
ideas/hints on how solve problem?

have 1 thread , 1 thread listening udp. can store results in thread safe collection keyboard thread read or wait on.


Comments

Popular posts from this blog

Linux vanilla kernel on QEMU and networking with eth0 -

rdbms - what exactly the undo information lives in oracle? -

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -