spring 配置异步要点
来源:互联网 发布:看新闻赚钱的软件 编辑:程序博客网 时间:2024/05/16 05:53
一般可以简单的用@Async来配置一个异步方法。例如
1 /**
2 * 发送MIME格式的用户修改通知邮件
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 */
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:annotation-driven executor="myExecutor" scheduler="myScheduler" />
<task:executor id="myExecutor" pool-size="50" />
<task:scheduler id="myScheduler" pool-size="1000" />
<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.
核心还是在最后。
在配置文件的前面加上
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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">
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了
0 0
- spring 配置异步要点
- spring 配置异步要点 @Async
- spring 配置异步要点 @Async
- spring 配置异步要点(转载)
- spring中异步配置
- struts1、spring、hibernate整合配置要点
- .net 异步要点
- spring事件机制——异步配置
- 在spring-mvc.xml里配置异步
- spring aspectj aop的配置内建逻辑和要点
- Spring异步
- spring异步
- spring aop 要点
- Spring 要点总结
- spring aop 要点
- 【spring AOP 要点】
- spring注入类型要点
- spring学习要点
- MZ Training 2014 #4 B题
- A think of myself
- Jupiter Atacks!
- 第7周项目2计算圆柱体表面积
- 同时寻找最大数和最小数的最优算法 第二大数
- spring 配置异步要点
- CalTech machine learning, video 14 note(Support Vector Machine)
- 4K技术
- java学习--你不得不知道的Eclipse使用技巧
- 淄尊鬃奏足砖茁姿仔奏组紫紫自坐祝赘嘴
- 并联电阻值
- 15个初学者必看的基础SQL查询语句
- ViewPager onPageChangeListener总结
- Character frequency