I have a client that receive cyclically data form a server
while (true) {
System.out.println(in.readLine());
}
I want to set a timer of 5 sec to exit from the loop when the time is expired. I have search a lot but I haven not found anything that can help me.
I have tried with the Timer class but I found only example to schedule the execution of a task.
Another thing I tried is to use System.currentTimeMillis() but since the in.readLine() is blocking I can not break the loop and go above with the execution.
Thank you!