I'm making an application that simulates a simple game. It is necessary to limit the players, so they have 60 seconds to enter their answers. I have a problem if they don't type anything and the time limit expires, then it's necessary to close the Scanner (System.in) that I opened so that they could enter their answers, and give 0 points to one who did not respond in time. If anyone has a solution for me, please help me.
Asked
Active
Viewed 1,724 times
2
-
1This should help you http://stackoverflow.com/questions/5853989/time-limit-for-an-input – Dobbo1989 Sep 17 '12 at 20:50
-
I've seen it, does not work for me. Input stream remain blocked so it cant be done another entry from the users that I need when game continous. I tried with threads but cant interrupt a thread which performs input and it continues to run in the background, even i call Thread.interrupt()... – user1670000 Sep 17 '12 at 21:11
-
The detailed answer is mentioned in the link: https://stackoverflow.com/questions/5853989/time-limit-for-an-input – Durga Prasad Behera May 15 '19 at 01:46
1 Answers
1
Try TimerTasks, check out http://docs.oracle.com/javase/7/docs/api/java/util/TimerTask.html

Odomontois
- 15,918
- 2
- 36
- 71

sharadendu sinha
- 827
- 4
- 10