播放框架覆盖默认调度程序

时间:2015-03-04 14:38:25

标签: java playframework

我会问我做错了什么,function2()按预期工作,但函数1()没有。我期望覆盖默认调度程序会在没有指定执行上下文的情况下影响promises,但是function1()在我的PC上运行大约8个线程而不依赖于application.conf。以下配置仅用于测试。

我的application.conf:

play {
  akka {
    akka.loggers = ["akka.event.Logging$DefaultLogger", "akka.event.slf4j.Slf4jLogger"]
    loglevel = WARNING
    actor {
      default-dispatcher = {
        fork-join-executor {
          parallelism-min = 1
          parallelism-factor = 1
          parallelism-max = 1
        }
      }
    }
  }
}

代码:

public static F.Promise<Result> function1() {
    Logger.underlying().debug("Executing: {}", "start");
    F.Promise<Result> promise1 = F.Promise.promise(() -> {System.out.println("promise1");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise2 = F.Promise.promise(() -> {System.out.println("promise2");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise3 = F.Promise.promise(() -> {System.out.println("promise3");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise4 = F.Promise.promise(() -> {System.out.println("promise4");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise5 = F.Promise.promise(() -> {System.out.println("promise5");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise6 = F.Promise.promise(() -> {System.out.println("promise6");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise7 = F.Promise.promise(() -> {System.out.println("promise7");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise8 = F.Promise.promise(() -> {System.out.println("promise8");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise9 = F.Promise.promise(() -> {System.out.println("promise9");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise10 = F.Promise.promise(() -> {System.out.println("promise10");Thread.sleep(6000); return "";}).map(Results::ok);
    F.Promise<Result> promise11 = F.Promise.promise(() -> {System.out.println("promise11");Thread.sleep(6000); return "";}).map(Results::ok);

    Logger.underlying().debug("Executing: {}", "stop");

    return promise11;
}

public static F.Promise<Result> function2() {
    Logger.underlying().debug("Executing: {}", "start");
    ExecutionContext executionContext = Akka.system().dispatchers().lookup("play.akka.actor.default-dispatcher");
    F.Promise<Result> promise1 = F.Promise.promise(() -> {System.out.println("promise1");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise2 = F.Promise.promise(() -> {System.out.println("promise2");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise3 = F.Promise.promise(() -> {System.out.println("promise3");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise4 = F.Promise.promise(() -> {System.out.println("promise4");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise5 = F.Promise.promise(() -> {System.out.println("promise5");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise6 = F.Promise.promise(() -> {System.out.println("promise6");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise7 = F.Promise.promise(() -> {System.out.println("promise7");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise8 = F.Promise.promise(() -> {System.out.println("promise8");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise9 = F.Promise.promise(() -> {System.out.println("promise9");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise10 = F.Promise.promise(() -> {System.out.println("promise10");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);
    F.Promise<Result> promise11 = F.Promise.promise(() -> {System.out.println("promise11");Thread.sleep(6000); return "";}, executionContext).map(Results::ok);

    Logger.underlying().debug("Executing: {}", "stop");

    return promise11;
}

0 个答案:

没有答案