2013-01-31 53 views
1

号演员池中的线程在我的演员之一反应方法I输出线程池做:限制为1

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参数。

我的期望是我现在应该只看到一个线程,但我还是看到负荷。有任何想法吗?

回答

2

简短的回答

尝试用

-Dactors.corePoolSize=1 

说明运行VM

ForkJoinScheduler,这是运行Java 1.6或更高版本的大多数操作系统默认的调度,使用DrainableForkJoinPool下覆盖了,据我所知,忽略maxPoolSize财产。见ForkJoinSchedulermakeNewPool方法和constructorDrainableForkJoinPool