首页 > 其他 > 详细

@Async的使用

时间:2017-06-27 21:35:28      阅读:238      评论:0      收藏:0      [点我收藏+]

从Spring3.x 开始,加入@Async这个注解,用户异步线程处理,使用起来很方便。

使用配置如下:spring-task.xml

<task:executor id="executor" pool-size="5" />
<task:scheduler id="scheduler" pool-size="10" />
<task:annotation-driven executor="executor" scheduler="scheduler" />

使用处:

在被调用的方法上增增加@Async的注解,无返回值实例片段

@Async
@Override
public void sendMessage(Long phone, Integer type, Integer batch) throws Exception {}

有返回值:

@Async
@Override
public Future<String> sendMessage(Long phone, Integer type, Integer batch) throws Exception{

        ....

        return AsyncResult<String>("SUCCESS"); 
} 

注意事项

使用@Async注解的方法必须是直接被调用的那个方法,如果是一个内部调用方法的私有方法,该注解不会生效。

@Async的使用

原文:http://www.cnblogs.com/blacksonny/p/7087184.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!