将actor池的线程数限制为1

时间:2013-01-31 16:24:08

标签: multithreading scala threadpool

在我的一个actor中,我通过执行以下方式输出线程池:

val scalaThreadSet = asScalaSet(Thread.getAllStackTraces().keySet());
scalaThreadSet.foreach(element => Console.println("Thread=" + element + ",state=" + 
                    element.getState())) 

我看到一堆线程:

Thread=Thread[ForkJoinPool-1-worker-6,5,main],state=WAITING
Thread=Thread[Signal Dispatcher,9,system],state=RUNNABLE
Thread=Thread[ForkJoinPool-1-worker-10,5,main],state=RUNNABLE
Thread=Thread[ForkJoinPool-1-worker-13,5,main],state=WAITING
Thread=Thread[ForkJoinPool-1-worker-7,5,main],state=WAITING
Thread=Thread[ForkJoinPool-1-worker-9,5,main],state=WAITING
Thread=Thread[ForkJoinPool-1-worker-14,5,main],state=WAITING

我希望将线程池的大小减少到一个并且只看到一个线程,所以我传入:

所以我传入:

-Dactors.maxPoolSize=1 

作为VM参数。

我的期望是我现在应该只看到一个线程,但我仍然看到负载。有什么想法吗?

1 个答案:

答案 0 :(得分:2)

简短回答

尝试使用

运行VM
-Dactors.corePoolSize=1

<强>解释

运行Java 1.6或更高版本的大多数操作系统的默认调度程序ForkJoinScheduler使用DrainableForkJoinPool来涵盖哪些内容,据我所知,忽略了maxPoolSize属性。请参阅ForkJoinScheduler的{​​{3}}方法和DrainableForkJoinPool的{​​{3}}。

相关问题