سؤال

I'm calling a method from Ajax... and 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);
  }
});

On Application.java

I call a method that does a huge computation and this spend a lot of time...

@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));
}

After 50 minutes of processing more or less I got this timeout error:

[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]

Somebody knows a better manner to do that?

Thanks in advance.

هل كانت مفيدة؟

المحلول

You can refer this link

This error comes because the play server doesnt get the enough thread to process the request. Since the method fooDAO.methodOfHugeComputation() takes a lot of time to process whiich doesnt releases the threads from your thread pool, thats why you need to increase your thread pool and processes by configuring your akka actors. You have a blocking I/O method so you need to use highly syncronous configuration.Check Out following documentation http://www.playframework.com/documentation/2.1.x/ThreadPools.

Also check whether you application is not consuming high memory which can also be a reason for not creating new threads for the process.

Also refer this links

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top