我正在让Scala函数更并行,这样它就可以从多个线程调用,真正地并行运行。我正在使用profiler,我看到我的函数compute正在等待AbstractQueuedSynchronizer$ConditionObject的388毫秒。根据分析器的说法,等待发生在scala.Option.filter中。
我试着查看javap的字节码,但我没有看到任何AbstractQueuedSynchronizer。
我使用ExecutorService运行我的代码
{ (1 to 24) ++ (24 to 1 by -1) }.foreach { threads =>
val executorService = Executors.newFixedThreadPool(threads)
compute(executorService, s"Threads $threads")
executorService.shutdown()
executorService.awaitTermination(10, TimeUnit.SECONDS)
}我希望没有等待,没有AbstractQueuedSynchronizer。AbstractQueuedSynchronizer是从哪里来的?
发布于 2019-06-05 04:08:55
public abstract class java.util.concurrent.locks.AbstractQueuedSynchronizer extends java.util.concurrent.locks.AbstractOwnableSynchronizer implements java.io.Serializable
它来自于Java并发库,涉及到运行时的并发代码。
https://stackoverflow.com/questions/56445264
复制相似问题