Play Framework异步控制器

时间:2014-12-06 11:57:25

标签: asynchronous playframework-2.3

我遇到播放异步请求处理问题。出于测试目的,我已经编写了以下控制器方法。当我对asyncSleep发出4个后续请求时,我的播放实例会被阻塞,直到其中一个asyncSleep请求返回。

public static Promise<Result> asyncSleep() {
   Promise<Integer> promiseOfInt = Promise.promise(new Function0<Integer>() {
      public Integer apply() {
         try {
            Thread.sleep(60000L);
         } catch(Exception e) {
            e.printStackTrace();
         }
         return 9;
       }
    });
    return promiseOfInt.map(new Function<Integer, Result>() {
        public Result apply(Integer i) {
            return ok("asyncSleep ok " + System.currentTimeMillis());
        }
    });
}

我做错了吗?

0 个答案:

没有答案
相关问题