2014-09-01 53 views
0

我在GWT中的StockPriceService示例中挣扎。我已经设法让它运行,并且执行了步骤2(http://www.gwtproject.org/doc/latest/tutorial/RPC.html),在那里我实现了StockPriceServerImpl类。(GWT教程)StockPriceServiceImpl :: getPrices()被调用5次

public class StockPriceServiceImpl extends RemoteServiceServlet implements StockPriceService { 

它的工作原理,也就是被称为OK,但这里的问题:

我宣布在班上就像一个变量:

private ConfigurationLoader confLoader = null; 

,然后在getPrices()方法:

if (confLoader == null) { 
    System.out.println("----creating a conf loader instance ---"); 
    confLoader = new ConfigurationLoader("192.168.2.199","8888"); 
} 

的问题,当我运行它是:

消息“----创建conf加载器...”被打印5(五)次....然后它显然运行OK ...?

任何想法发生了什么?

回答

0

好吧,事实证明这是我的错误。由于对getPrices()的调用是异步的,并且在调用之间仅以1秒发送,并且ConfigurationLoader的构建比此慢,所以在ConfigurationLoader完成之前我有5个调用。它现在效果更好!