spring-对线程池的支持
来源:互联网 发布:php ini set 不起作用 编辑:程序博客网 时间:2024/05/24 04:32
<!-- 线程的配置文件: corePoolSize: 线程池维护线程的最少数量 keepAliveSeconds 线程池维护线程所允许的空闲时间 maxPoolSize 线程池维护线程的最大数量 queueCapacity 线程池所使用的缓冲队列 -->
<bean id ="taskExecutor" class ="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor" >
<property name ="corePoolSize" value ="10" />
<property name ="maxPoolSize" value ="50" />
<property name ="keepAliveSeconds" value ="300" />
<property name ="queueCapacity" value ="1000" />
<property name="rejectedExecutionHandler">
<bean class="java.util.concurrent.ThreadPoolExecutor$CallerRunsPolicy" />
</property>
</bean>
spring 配置异步要点
3 */
4 @Async
5 public void sendNotificationMail(Map keyValue,String toAddress,String subJect,String templateName) {
6
7 String[] toList={toAddress}; sendNotificationMail(keyValue,toList,subJect,templateName) ;
8 }
但是这么做只是简单做法,大概积累3封邮件以后就会堵塞线程。
所以要加上配置文件
<task:executor id="myExecutor" pool-size="50" />
<task:scheduler id="myScheduler" pool-size="1000" />
但是只这么做,会报错
Caused by: org.xml.sax.SAXParseException: The prefix "task" for element "task:annotation-driven" is not bound.
核心还是在最后。
在配置文件的前面加上
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
xmlns:jdbc="http://www.springframework.org/schema/jdbc" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa"
xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-3.1.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd"
default-lazy-init="true">
里面的task段落加上就OK了
- spring-对线程池的支持
- spring对Junit的支持、spring对Aop的支持
- Spring对Hibernate的支持
- spring对DAO的支持
- Spring对JDBC的支持
- spring对AOP的支持
- Spring 对 JMS的支持
- Spring对EJB的支持
- Spring对国际化的支持
- Spring对AOP的支持
- Spring 对JMS的支持
- Spring对JDBC的支持
- spring对Hibernate的支持
- spring对事务的支持
- Spring对AOP的支持
- Spring对jndi的支持
- spring对邮件的支持
- Spring对JDBC的支持
- 正则表达式
- iOS objection 依赖注入
- git修改ssh默认端口号
- Lucene的评分(score)机制的简单解释
- Spring MVC
- spring-对线程池的支持
- mfc CRgn 画椭圆对话框
- C# 中普通类、抽象类、接口之间的区别
- 关于TextWatcher编辑框监听器的参数问题
- 使用SIPP来进行SIP压力测试(一)
- 远程服务器上传文件
- Java中 Class.getSimpleName()的作用
- 国外博士论文下载~
- 字符流与字节流的转换