Reputation:
I want to execute a specific method which contains a service call. As it includes a service call , it will take some time for execution. I want to add a timer which will keep program in wait till that method completes its executiuon. Any work around for this?
Upvotes: 0
Views: 105
Reputation: 1210
Sheduler
Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand(){
@Override
public void execute() {
// code here
}
Upvotes: 0
Reputation: 135992
You can organize an asynchroneous method execution with a timeout with java.util.concurrent
package
ExecutorService executorService = ...
Object res = executorService.submit(new Callable<Object>() {
public Object call() throws Exception {
... your logic
}
}).get(timeout, TimeUnit.MILLISECONDS);
Upvotes: 1
Reputation: 30809
You can use a separate thread to call that service and using join()
method of Thread class, you can force main program to wait until that thread finishes the execution.
Upvotes: 1