[英]What happens if my Java ThreadPoolTaskExecutor gets called more than the “maxPoolSize” setting?
I'm using Java 6 with Spring 3.2.11.RELEASE and JBoss 7.1.3.Final. 我正在将Java 6与Spring 3.2.11.RELEASE和JBoss 7.1.3.Final一起使用。 I have this in my Spring application context file
我的Spring应用程序上下文文件中有这个
<!-- Manages thirdparty threads -->
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
<property name="threadFactory" ref="thirdpartyThreadFactory"/>
<property name="maxPoolSize" value=“10” />
<property name="corePoolSize" value=“5” />
</bean>
<bean id="thirdpartyThreadFactory" class="org.springframework.scheduling.concurrent.CustomizableThreadFactory">
<constructor-arg value="thirdparty-"/>
</bean>
My question is, if I call the taskExecutor's execute method 300 times given the above settings, what happens to the other 290 threads when the first 10 get queued up? 我的问题是,如果给定上述设置,如果我调用taskExecutor的execute方法300次,那么当前10个线程排队时,其他290个线程会怎样? Do they get dropped or is it just that 10 threads are executed at a time?
它们会被丢弃还是只是一次执行10个线程?
The maxPoolSize
defines the maximum number of concurrent running threads. maxPoolSize
定义并发运行线程的最大数量。 So if you submit more tasks than that number, they will be queued depending on the queue settings (eg you can limit the queue size by calling setQueueCapacity()
). 因此,如果您提交的任务数量超过该数目,则它们将根据队列设置进行排队(例如,您可以通过调用
setQueueCapacity()
来限制队列大小)。
maxPoolSize only defines the number of thread which can run simultaneously. maxPoolSize仅定义可以同时运行的线程数。 So it is a limit on the number of threads your code is going to generate.
因此,这是对代码将要生成的线程数量的限制。 The rest of the tasks are not dropped but are in queue and gets executed as soon as a thread frees.
其余任务不会被丢弃,而是排在队列中,并在线程释放后立即执行。
For eg. 例如。 if you had maxPoolSize to 1 then all the tasks will get executed sequentially.
如果您将maxPoolSize设置为1,则所有任务将按顺序执行。 In your case in a batch of 10 depending on the time taken by each task.
在您的情况下,每批任务要花费10个时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.