并发方案中替换了Spring Command Object属性

时间:2014-07-08 08:52:21

标签: java spring-mvc concurrency yui

我使用YUI2 Connect utils向Spring 2 Web MVC Web应用程序发送了几个异步请求。请求要求Id的计算结果。我的控制器中的接收方法有一些长时间运行的操作来计算请求中给定ID的结果。当记录客户端和服务器时,我意识到服务器端的结果与客户端的结果不匹配,即客户端的结果与不同的ID匹配,而不是服务器端的结果。我发现问题是id在控制器方法中混淆了。

客户端方法如下所示:

for ( var i = 0; i < array.length; i++) {
 var request = YAHOO.util.Connect.asyncRequest('GET', myURL+ array[i],
  myCallback);
}

控制器方法看起来像这样。

public ModelAndView calculate(HttpServletRequest request,
        Command command, BindException errors) throws Exception {
  MyCommand myCommand = (MyCommand) command;
  //myCommand object contains id from request, used in both operations
  Result1 result1 = doLongRunningOperation(myCommand);
  //now the id in myCommand is different from the beginning but not
  //changed in the operation above
  Result2 result2 = doAnotherLongRunningOperation(result1);
  return buildModelAndView(result2);
}

我认为Spring会以线程安全的方式处理这种情况,但这里看起来有所不同。我错过了配置吗?我目前通过深度复制命令对象来处理它,这有用,但这不应该是要走的路,对吗?

0 个答案:

没有答案