How to wait for user console input OR (!!!) changing of a variable contents (threads used)

T

Tobias Merler

I have two threads like show below. In the inner thread I want to wait for user input
from console OR and this is the tricky question alternatively for the change of a
particular contents of a variable in the outer thread (here: variable "state").

If the user enter something or if the contents change
to a special value (e.g. 'a') the inner thread should move on.
If both event are not happening the thread should stay until one of both became true.
How do I implement this most easily with Java ?


char state = 'x';
....
InnerThread = new Thread(new Runnable() {
public void run() {
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
...
option = buf.readLine() || (state == 'a'); <==== This is obviously not working!!
....
} } );
...
state = 'a';
...


Regards
Tobias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,262
Messages
2,571,052
Members
48,769
Latest member
Clifft

Latest Threads

Top