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

Discussion in 'Java' started by Tobias Merler, Aug 25, 2003.

  1. 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
     
    Tobias Merler, Aug 25, 2003
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. penny336
    Replies:
    4
    Views:
    570
    osmium
    Jan 15, 2004
  2. Huey

    How to make "fork/wait" to WAIT longer?

    Huey, Mar 1, 2004, in forum: C Programming
    Replies:
    1
    Views:
    2,014
    -berlin.de
    Mar 1, 2004
  3. Sean W
    Replies:
    2
    Views:
    2,312
    Oliver Wong
    Aug 31, 2006
  4. Replies:
    4
    Views:
    579
    Jim Langston
    Dec 1, 2005
  5. Replies:
    0
    Views:
    221
Loading...

Share This Page