Spring中配置執行緒池ThreadPoolExecutor參考
阿新 • • 發佈:2019-02-06
<bean id="executorService" class="java.util.concurrent.ThreadPoolExecutor"> <constructor-arg value="5" index="0"/> <constructor-arg value="10" index="1"/> <constructor-arg value="60" index="2"/> <constructor-arg value="SECONDS" index="3" type="java.util.concurrent.TimeUnit"/> <constructor-arg index="4"> <bean class="java.util.concurrent.LinkedBlockingQueue"> <constructor-arg value="100"/> </bean> </constructor-arg> <constructor-arg index="5"> <bean class="java.util.concurrent.ThreadPoolExecutor$DiscardOldestPolicy"/> </constructor-arg> </bean>
ExecutorService executorService = BeanUtil.getBean("excutorService"); executorService.execute(new Runnable());