+ 2

Please help me in implementing the below "Timeout" scenario in java using threads

User should prompt to give some input value. if user enters some input before 1min , "Congratulations" has to be printed. Otherwise "Better luck next time " has to be printed. please help. what logic I need to use?

19th Apr 2017, 7:39 AM
Sribalaji A
Sribalaji A - avatar
2 Réponses
+ 3
You need to place time counter in second thread and when it reach given value - write a message and close first thread which still awaiting for input.
19th Apr 2017, 9:01 AM
Jeth
Jeth - avatar
+ 3
Also if user do input in time you just close thread with counter.
19th Apr 2017, 9:02 AM
Jeth
Jeth - avatar