This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Program exsiting cleanly  RSS feed

 
hennie louw
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have a big favor to ask.
I am writing a app that will run in the background in eg
an command prompt.
What this app has many Threads running and handling very sensitve data , What i want to ask if there is a way to catch a input from the keyboard and according to what was presses ingonre it or exit the app gracefuly.
Any pionters on this would be appreciated
Thanks
 
Frank Carver
Sheriff
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The usual way to do this is to dedicate one thread to listening to the keyboard (System.in, I assume). If it gets the "stop" character it should call a method on each thread object in the system which sets some sort of internal state variable and then stop itself. Whenever each thread gets to a reasonable place to stop, it should check the state variable to see if it has been asked to stop, and if so, so do. When the last one has gone, your application should exit
 
hennie louw
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all i've tryed what you guys said , this is how th e code looks

Now this look fine , but the problem is that it only prints you the value of input after i have hit enter , how can i get it to print the values as they com out ???
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!