I have a function like this:
public boolean doLogin() {
try {
somemethodForLogin();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
In this case I want to return false
or throw an exception if somemethodForLogin()
takes more time than expected, say 8 seconds. How can I do this?
I added something like this just before somemethodForLogin()
:
new java.util.Timer().schedule(
new java.util.TimerTask() {
@Override
public void run() {
System.out.println("Returning after 8 seconds wait");
}
}, 8000);
But it comes into this always, even if the call is success.