I have an interface method boolean right(), if it isn’t “answering” in a second, it should return false.
I have an interface method boolean right() , if it isn’t answering in a
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Yes, this is possible with e.g.
java.util.concurrent.Future<V>(the standardinterfaceto represents the result of an asynchronous computation of typeV), combined with the methodget(long timeout, TimeUnit unit). The method may throwTimeoutException, among other exceptions, but otherwise returns the computed result on normal execution.In this case you want a
Future<Boolean>, withget(1, TimeUnit.SECONDS)within atry-catchblock, handlingTimeOutExceptionper your specification.Available concrete implementations are
FutureTask<V>andSwingWorker<T,V>. If this is within the context of Swing application, then you’d want to use the latter.See also