0

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?

4

3 回答 3

1

您可以使用单独的线程来调用该服务并使用join()Thread 类的方法,您可以强制主程序等待该线程完成执行。

于 2013-07-10T05:08:51.560 回答
1

您可以使用java.util.concurrent包超时组织异步方法执行

    ExecutorService executorService = ...
    Object res = executorService.submit(new Callable<Object>() {
        public Object call() throws Exception {
            ... your logic
        }
    }).get(timeout, TimeUnit.MILLISECONDS);
于 2013-07-10T05:15:47.043 回答
0

调度器

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand(){

@覆盖

公共无效执行(){

// 这里的代码

}

于 2013-07-10T05:57:40.973 回答