有什么方法可以在 Scala 或 Play Framework 中获取线程池指标?
在 scala.concurrent 我只能访问
ExecutionContextExecutor
它没有返回事件连接、排队任务计数等的方法。
我不能将它转换为可以访问执行程序的实现,因为它们是私有(private)的。
感谢您的帮助。
最佳答案
我是这样解决的:
val field: Field = Class.forName("scala.concurrent.impl.ExecutionContextImpl").getDeclaredField("executor")
field.setAccessible(true)
val executor: ForkJoinPool = field.get(ExecutionContext.global).asInstanceOf[ForkJoinPool]
我知道它目前只能与 ForkJoinPool 一起使用,但使用一些模式匹配等。它可以变得更通用,也可以与 ThreadPoolExecutor 一起使用。
关于Scala/Play 线程池指标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41393061/