Spring scheduled tasks and asynchronous processing

import org.springframework.scheduling.annotation.Async;

import org.springframework.scheduling.annotation.Scheduled;

import org.springframework.stereotype.Component;

 

 

@Component

public class MailUtility {

 

//@Scheduled(cron="0/5 * *  * * ? ")

@Async

public void sendMail(){

 

 System.out.println("I Will be formatting html mail and sending it");

 

try {

    Thread.sleep(10000);

 

} catch (InterruptedException e) {

 

     e.printStackTrace ();

}

 

System.out.println("Asynchronous method call of send email — Complete");

 

}

 

}

 

 

 

In the configuration file:

 

    <task:executor id="executor" pool-size="5" />  

    <task:scheduler id="scheduler" pool-size="10" />  

    <task:annotation-driven executor="executor" scheduler="scheduler" />  

 

 

http://www.springframework.org/schema/task  

http://www.springframework.org/schema/task/spring-task-3.0.xsd

 

 

 xmlns:task="http://www.springframework.org/schema/task

 

 异步处理使用在较长时间的处理中,先返回界面。

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327041396&siteId=291194637