53 lines
3.4 KiB
XML
53 lines
3.4 KiB
XML
|
|
<?xml version="1.0" encoding="UTF-8"?>
|
|||
|
|
<beans xmlns="http://www.springframework.org/schema/beans"
|
|||
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|||
|
|
xmlns:context="http://www.springframework.org/schema/context"
|
|||
|
|
xmlns:aop="http://www.springframework.org/schema/aop"
|
|||
|
|
xmlns:tx="http://www.springframework.org/schema/tx"
|
|||
|
|
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
|||
|
|
http://www.springframework.org/schema/beans/spring-beans.xsd
|
|||
|
|
http://www.springframework.org/schema/context
|
|||
|
|
http://www.springframework.org/schema/context/spring-context.xsd
|
|||
|
|
http://www.springframework.org/schema/tx
|
|||
|
|
http://www.springframework.org/schema/tx/spring-tx.xsd
|
|||
|
|
http://www.springframework.org/schema/aop
|
|||
|
|
http://www.springframework.org/schema/aop/spring-aop.xsd">
|
|||
|
|
|
|||
|
|
|
|||
|
|
<context:component-scan base-package="com.mobile,com._3e,com.univ3e,com.dub">
|
|||
|
|
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
|
|||
|
|
</context:component-scan>
|
|||
|
|
|
|||
|
|
|
|||
|
|
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
|
|||
|
|
<property name="location" value="classpath:settings.properties" />
|
|||
|
|
<property name="fileEncoding" value="utf-8" />
|
|||
|
|
</bean>
|
|||
|
|
|
|||
|
|
<!-- 线程池 -->
|
|||
|
|
<bean id="taskExecutor" class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
|
|||
|
|
<!-- 核心线程数 -->
|
|||
|
|
<!-- 每个任务需要tasktime秒处理,则每个线程每钞可处理1/tasktime个任务。 系统每秒有tasks个任务需要处理,则需要的线程数为:tasks/(1/tasktime),即tasks*tasktime个线程数。 假设系统每秒任务数为100~1000,每个任务耗时0.1秒,则需要100*0.1至1000*0.1,即10~100个线程。 那么corePoolSize应该设置为大于10,具体数字最好根据8020原则,即80%情况下系统每秒任务数, 若系统80%的情况下第秒任务数小于200,最多时为1000,则corePoolSize可设置为20。 -->
|
|||
|
|
<property name="corePoolSize" value="5" />
|
|||
|
|
<!-- 最大线程数 -->
|
|||
|
|
<!-- 当系统负载达到最大值时,核心线程数已无法按时处理完所有任务,这时就需要增加线程。 每秒200个任务需要20个线程,那么当每秒达到1000个任务时, 则需要(1000-queueCapacity)*(20/200),即60个线程,可将maxPoolSize设置为60。 -->
|
|||
|
|
<property name="maxPoolSize" value="10" />
|
|||
|
|
<!-- 队列最大长度 -->
|
|||
|
|
<!-- 任务队列的长度要根据核心线程数,以及系统对任务响应时间的要求有关。 队列长度可以设置为(corePoolSize/tasktime)*responsetime: (20/0.1)*2=400,即队列长度可设置为400。 -->
|
|||
|
|
<property name="queueCapacity" value="200" />
|
|||
|
|
<!-- 线程池维护线程所允许的空闲时间 -->
|
|||
|
|
<!-- 线程数量只增加不减少也不行。当负载降低时,可减少线程数量,如果一个线程空闲时间达到keepAliveTiime, 该线程就退出。默认情况下线程池最少会保持corePoolSize个线程。 -->
|
|||
|
|
<property name="keepAliveSeconds" value="300" />
|
|||
|
|
<!-- 线程池对拒绝任务(无线程可用)的处理策略 -->
|
|||
|
|
<property name="rejectedExecutionHandler">
|
|||
|
|
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />
|
|||
|
|
</property>
|
|||
|
|
</bean>
|
|||
|
|
|
|||
|
|
<bean id="threadPool" class="org.springframework.core.task.SimpleAsyncTaskExecutor">
|
|||
|
|
<property name="daemon" value="true" />
|
|||
|
|
<property name="concurrencyLimit" value="300" />
|
|||
|
|
<property name="threadNamePrefix" value="SERVICE" />
|
|||
|
|
</bean>
|
|||
|
|
|
|||
|
|
</beans>
|