播放框架中的调度:增加线程数

时间:2016-11-03 14:43:16

标签: multithreading scala playframework akka

我的服务中有一个简单的任务(播放2.5.4):

@Singleton
class BalanceService @Inject()(val contexts: Contexts, as: ActorSystem) {

    private val after = FiniteDuration(5, SECONDS)
    private val interval = FiniteDuration(5, SECONDS)

    private val checkBalanceTask = as.scheduler.schedule(after, interval) {
        logger.debug(s"BalanceUpdate")
    }(contexts.miscCtx)

...

contexts.miscCtx 是自定义上下文(在application.conf中),如

misc {
    fork-join-executor {
      parallelism-factor = 1
      parallelism-max = 24
      task-peeking-mode = LIFO
    }
  }

因此,每次执行任务时,我都会在日志中找到一行:

17:26:44.128 [application-contexts.misc-65  ] DEBUG model.services.BalanceService - BalanceUpdate
17:26:49.128 [application-contexts.misc-66  ] DEBUG model.services.BalanceService - BalanceUpdate
17:26:54.129 [application-contexts.misc-67  ] DEBUG model.services.BalanceService - BalanceUpdate

线程数不断增加,但线程总数相同(我使用性能分析工具检查)。我的设置可能有什么问题?似乎每次创建和销毁线程而不是重用旧线程。

1 个答案:

答案 0 :(得分:0)

您想使用Intent intent = new Intent(activity, clazz); activity.startActivity(intent); activity.overridePendingTransition(android.R.anim.slide_in_left, android.R.anim.slide_out_right); 而不是thread-pool-executor