0

我正在从 Ajax 调用一个方法...和 ​​PlayFramework 2.1.3

$.ajax({
  type: "POST",
  contentType: "application/json; charset=utf-8",
  dataType: "json",
  url: "/examplefoo",
  data: JSON.stringify(exampleArray),
  success: function(data) {
    doSomething();
  },
  error: function(e) {
    console.log(e);
  }
});

在 Application.java 上

我调用了一个进行大量计算的方法,这会花费大量时间......

@BodyParser.Of(play.mvc.BodyParser.Json.class)
public static Result examplefoo() throws SQLException, IOException {
    DAOFoo fooDAO = new DAOFoo();
    result = fooDAO.methodOfHugeComputation();

    return ok(play.libs.Json.toJson(result));
}

经过 50 分钟或多或少的处理后,我得到了这个超时错误:

[error] application -

! @6fnm1gafo - Internal server error, for (POST) [/examplefoo] ->

play.api.Application$$anon$1: Execution exception[[AskTimeoutException: Timed out]]
    at play.api.Application$class.handleError(Application.scala:289) ~[play_2.10.jar:2.1.3]
    at play.api.DefaultApplication.handleError(Application.scala:383) [play_2.10.jar:2.1.3]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$play$core$server$netty$PlayDefaultUpstreamHandler$$handle$1$1.apply(PlayDefaultUpstreamHandler.scala:143) [play_2.10.jar:2.1.3]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$play$core$server$netty$PlayDefaultUpstreamHandler$$handle$1$1.apply(PlayDefaultUpstreamHandler.scala:139) [play_2.10.jar:2.1.3]
    at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.3]
    at play.api.libs.concurrent.PlayPromise$$anonfun$extend1$1.apply(Promise.scala:113) [play_2.10.jar:2.1.3]
akka.pattern.AskTimeoutException: Timed out
    at akka.pattern.PromiseActorRef$$anonfun$1.apply$mcV$sp(AskSupport.scala:310) ~[akka-actor_2.10.jar:na]
    at akka.actor.DefaultScheduler$$anon$8.run(Scheduler.scala:193) ~[akka-actor_2.10.jar:na]
    at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:137) ~[akka-actor_2.10.jar:na]
    at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1417) ~[scala-library.jar:na]
    at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:262) ~[scala-library.jar:na]
    at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:975) ~[scala-library.jar:na]

有人知道更好的方法吗?

提前致谢。

4

1 回答 1

0

你可以参考这个链接

出现此错误是因为播放服务器没有获得足够的线程来处理请求。由于 fooDAO.methodOfHugeComputation() 方法需要大量时间来处理,而不会从线程池中释放线程,这就是为什么您需要通过配置 akka 角色来增加线程池和进程的原因。您有一个阻塞 I/O 方法,因此您需要使用高度同步的配置。请查看以下文档http://www.playframework.com/documentation/2.1.x/ThreadPools

还要检查您的应用程序是否没有消耗高内存,这也可能是不为进程创建新线程的原因。

另请参阅此链接

于 2013-10-14T06:16:57.857 回答