简体   繁体   English

如果我的Java ThreadPoolTask​​Executor被调用的次数超过了“ maxPoolSize”设置会发生什么?

[英]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.

相关问题 Java ThreadPoolExecutor [提交超过 MaxPoolSize] - Java ThreadPoolExecutor [Submit More Than MaxPoolSize] ThreadPoolTask​​Executor中corePoolSize和maxPoolSize的理想值应该是多少 - What should be ideal value of corePoolSize and maxPoolSize in ThreadPoolTaskExecutor Spring ThreadPoolTask​​Executor中corePoolSize和maxPoolSize有什么区别 - What is the difference between corePoolSize and maxPoolSize in the Spring ThreadPoolTaskExecutor 在 springboot async 中设置 maxpoolsize 会使我的 UI 仅对 5 个用户可用吗? - Setting maxpoolsize in springboot async will make my UI available only to 5 users? 使用JDBC设置高maxPoolSize时需要注意哪些风险/因素 - What are the risks / factors to watch when setting a high maxPoolSize with JDBC 在Java中调用方法后会发生什么 - What happens after a method is called in Java Android Java:在运行多个任务的AsyncTask中会发生什么? - Android Java : What happens in an AsyncTask with more than one task being operated? OnBeforeSave被调用但什么也没发生 - OnBeforeSave gets called but nothing happens 当消息到达服务器而不读取Java流时,消息会发生什么? - what happens to a message when it gets to a server without reading stream in java? 调用HttpURLConnection.getInputStream()两次以上会发生什么 - What happens by calling HttpURLConnection.getInputStream() more than twice
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM