欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

Zeroc Ice 学习笔记 - 异步调用

最编程 2024-07-16 16:00:16
...
【直播预告】程序员逆袭 CEO 分几步?

 Zeroc Ice 学习笔记--异步调用

AsyncResult result = helloWorldPrx.begin_sayHelloWorld();
while (true){
    System.out.println("is call request sent:"+result.isSent());
    if(result.isCompleted()){
        System.out.println("call finished,return :"+helloWorldPrx.end_sayHelloWorld(result));
        break;
    }else {
        System.out.println(" wait for finished");
        Thread.sleep(1000);
    }
}
ArrayList<AsyncResult> asyncResults = new ArrayList<>();
for(int i = 0 ;i<2;i++){
    asyncResults.add(helloWorldPrx.begin_sayHelloWorld());
}
while (!asyncResults.isEmpty()){
    Iterator<AsyncResult> iterable = asyncResults.iterator();
    while (iterable.hasNext()){
        AsyncResult asyncResult = iterable.next();
        if(asyncResult.isCompleted()){
            System.out.println(helloWorldPrx.end_sayHelloWorld(asyncResult));
            iterable.remove();
        }
    }
    Thread.sleep(1000);
}