一、打上标签
@Resource
private AsyncSendTest asyncSendTest;
@Test
public void testAsyncSend(){
System.out.println("异步调用开始");
asyncSendTest.doSomething();
System.out.println("异步调用结束");
}
@Service
public class AsyncSendTest {
@Async
public void doSomething(){
System.out.println("异步处理中....");
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("异步处理结束");
}
}
===========输出结果:============
异步调用开始
异步处理中....
异步处理结束
异步调用结束
二、配置spring task executor
<beans 增加 :xmlns:task="http://www.springframework.org/schema/task"
xsi:schemaLocation="http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"/>
<task:executor id="executor" pool-size="10"/>
<task:annotation-driven executor="executor" proxy-target-class="true"/>
异步调用开始
异步调用结束
异步处理中....
异步处理结束