Results 1 to 2 of 2
  1. #1
    SYOB SYOT's Avatar
    SYOB SYOT is offline SYOB SYOT
    Join Date
    Oct 2016
    Posts
    1
    Rep Power
    0

    Question How to allow input for two threads from the console?

    Hay people,
    i have a question.

    Lets say i have a class "a", and class a creates a class "b" in the new thread.
    Class a is like a command prompt, it accepts input from the user in infinite loop, and gives that input to the thread of class b, and this thread handles that input, while thread of class a can accept new input and create a new instance of thread of class b for the next user command.

    Thread of class b usually does not require any additional input, unless in some special cases, where it requires some additional input from the user.
    The problem is that thread a is constantly waiting for next users input in the console, and thread b wants to get users input also.

    If i program the thread b that it simply waits for users input too, than one line of input is deliver to thread b, and another to thread a, and than b, a, b, a...

    If i simply leave both threads waiting for user input.

    Usually it is required that thread b gets several lines of user input before it can complete.

    I was considering that i suspend thread a from thread b at the time thread B requires input, and resume thread a after thread b no lOnger requires it.

    But the problem is since thread a created thread b, thread b can not suspend thread a since it does not have reference to it.

    If i simply use thread.suspend method, it suspends thread b instead of thread a.

    So, how can i solve this, so that i can suspend thread a until thread b is done reading from the console?

    Or if both threads are waiting for the input from the console, is there a way that i prevent thread a from getting it until thread b is done?

    Thank you for your time
    Last edited by SYOB SYOT; 10-15-2016 at 02:09 AM. Reason: SPELLING

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    20,003
    Rep Power
    33

    Default Re: How to allow input for two threads from the console?

    What have you tried?

    How to allow input for two threads from the console?
    Treat the console as a resource and queue to use it.
    Last edited by Norm; 10-15-2016 at 03:00 AM.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. console freezes when working in different threads
    By johnmerlino in forum New To Java
    Replies: 4
    Last Post: 07-23-2014, 03:42 AM
  2. How to get input from Console
    By karma in forum New To Java
    Replies: 8
    Last Post: 08-13-2010, 09:32 PM
  3. how to take input from console in jsp
    By veena in forum New To Java
    Replies: 1
    Last Post: 05-06-2008, 04:39 AM
  4. How to read input from console
    By Java Tip in forum java.io
    Replies: 0
    Last Post: 04-16-2008, 10:57 PM
  5. Taking input from console
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-05-2007, 04:47 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •