GWT-异步调用延迟

GWT-异步调用延迟,gwt,asynchronous,Gwt,Asynchronous,我对GWT中的RPC调用有问题。 下面是一个示例代码段: 我的UI中有四列,其中effdate和enddate作为列标题。 这些值没有按顺序显示。第一列值显示在第三列中。 大多数情况下,订单会发生变化。随机显示 我猜每次计数对服务器端方法的RPC调用都会延迟。 通过调试服务器端方法,我发现我为第一个循环传递的effdate和end日期有时执行第二个或第三个。它正在洗牌 有人能帮我吗。我需要在代码中做哪些更改才能在UI中显示正确的值。 有什么想法吗 count=4; List fi

我对GWT中的RPC调用有问题。 下面是一个示例代码段:

我的UI中有四列,其中effdate和enddate作为列标题。 这些值没有按顺序显示。第一列值显示在第三列中。 大多数情况下,订单会发生变化。随机显示

我猜每次计数对服务器端方法的RPC调用都会延迟。 通过调试服务器端方法,我发现我为第一个循环传递的effdate和end日期有时执行第二个或第三个。它正在洗牌

有人能帮我吗。我需要在代码中做哪些更改才能在UI中显示正确的值。 有什么想法吗

    count=4;
    List finalList = new arrayList();
    for(i=0;i<count;count++)
   {
   effdate= list.get(countincr);
   enddate= list.get(countincr+1);
   //call to server side method to fetch values from DB by passing effdate and end date as    parameter.
   grp.ratecalc(startdate,enddate,new AsyncCallback<List<grVo>>()
  {
  public void onfailure(throwable caught)
  {
  sys.out.print("failure");
  }
  public void onsuccess(List<grVo> result)
 {
 List grpList= new GrpVO();

rate = result.get(0).getrate();
rate1 = result.get(0).getrate1();

grpList.setrate();
grpList.setrate1();

setting values in bean for  the remaining values in the result.

finalList.add(grpList);


if(finalList.size()== count)
{
//calling a method to populate the values
methoddisplay(finalList);

}
}
}
);
countincr+=2;

}  //end of for loop`
count=4;
List finalList=new arrayList();

对于(i=0;i您可以使用映射而不是
finallist
来跟踪请求和响应。
我对你的代码做了一些更改。(不完整。请做必要的更改)

int计数=4;
Map Map=newhashmap();

对于(int i=0;i您的代码无法工作。您将RCP调用视为同步的,但它是异步的。未定义四个调用中的哪一个将是第一个收到服务器响应的调用。您必须重新设计代码。同步调用和异步调用之间存在差异。如果您理解这一点,您的问题将得到解决。Thanks!!我刚开始使用GWT。我知道,一旦发出请求,异步调用就不会等待响应。上面的代码可以工作,但显示顺序是错误的。如何使它以正确的顺序执行?我必须循环许多未知数量的异步调用并以正确的顺序执行,我该怎么做?
int count=4;
Map<Integer,Object> map = new HashMap<Integer, Object>();
for(int i=0;i<count;count++)
{   final int index=i; 
    effdate= list.get(countincr);
    enddate= list.get(countincr+1);
    grp.ratecalc(startdate,enddate,new AsyncCallback<List<grVo>>()
            {
        public void onfailure(throwable caught) {
            sys.out.print("failure");
        }
        public void onsuccess(List<grVo> result){
            List grpList= new GrpVO();
            rate = result.get(0).getrate();
            rate1 = result.get(0).getrate1();
            grpList.setrate();
            grpList.setrate1();
            map.put(index, grpList);                
            //check all items are put on the map and populate values.
        }
            }
            );
    countincr+=2;
}