I have a method (say execute()), if it takes more than 10 secs(per say)to return response i need to reexecute it.
Kindly help me how to achieve this?
Thanks
I have a method (say execute()), if it takes more than 10 secs(per say)to return response i need to reexecute it.
Kindly help me how to achieve this?
Thanks
Something like
Object response;
start = System.currentTimeMillis();
response = execute();
if (System.currentTimeMillis() - start > 10000) {
response = execute();
}
? or
Object get() {
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Object> response = executor.submit(() -> {
return execute();
});
executor.shutdown();
executor.awaitTermination(10, TimeUnit.SECONDS);
if (executor.isTerminated()) {
return response.get();
}
executor.shutdownNow();
return get();
}