The moose likes Threads and Synchronization and the fly likes Threads and System.in Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Reply Bookmark "Threads and System.in" Watch "Threads and System.in" New topic
Author

Threads and System.in

luis gallo
Greenhorn

Joined: Aug 09, 2001
Posts: 4
I am trying to create 2 threads: thread1 does a process and keyboardThread accepts a user keyboard input. While the thread1 is running no user input should be accepted. When thread1 finishes keyboardThread should be active to accept a user input (for example like "stop"), for a specified given time, when a new thread1 will start, and blocking again user inputs.
To pause the keyboardThread a method called pause was created.
But how to put all this together?
Thanks a lot you guys for your help,
luis

here is the code:
[ April 02, 2003: Message edited by: Jim Yingst ]
raimondas zemaitis
Ranch Hand

Joined: Feb 23, 2001
Posts: 104
I'd suggest you look into "Producer - consumer" example in Java Tutorial at Sun's site.
This is almost identical situation with yours.
luis gallo
Greenhorn

Joined: Aug 09, 2001
Posts: 4
Thanks I saw that - but I discovered the problem. The System.in stream when closed is closed and you cannot open it any more. That's why I experienced some strange behavior.
Mr. C Lamont Gilbert
Ranch Hand

Joined: Oct 05, 2001
Posts: 1158

Yes, I think closing the reader also closes the stream it was reading. Try just closing the thread itself, or setting some variable in the thread that lets it know the next time it gets info, to ignore the info and just end.
 
IntelliJ Java IDE
 
subject: Threads and System.in
 
Threads others viewed
Need practical example of wait() and notify()
Synchronizing between two threads, one implements Runnable the other extends Thread
What happens to the static variable here ? Threads !
synchronized threads
Aboutt Daemon Threads
developer file tools