• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threads and System.in

 
luis gallo
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!