I am using joda-time for this kind of thing:
Maven:
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>1.6.2</version>
</dependency>
When prompted for input, enter the LocalDateTime variable:
LocalDateTime timeOut = new LocalDateTime().plusSeconds(15);
And loop until the user enters an input or timeout:
if (timeOut.isBefore(new LocalDateTime())) {
//throw your exception if this case happens
}
Before you start voting: this is just quickie: p
amuses
source
share