Original
join here set stop 3s
package com.jj.demo.service;
import org.springframework.stereotype.Service;
@Service
public class Asnycservice {
public void hello() throws InterruptedException {
Thread.sleep(3000);
System.out.println("数据在处理!!");
}
}
Console code
package com.jj.demo.controller;
import com.jj.demo.service.Asnycservice;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
@Controller
public class Asnycontrller {
// 注入service
@Autowired
Asnycservice asnycservice;
@RequestMapping("/hello")
@ResponseBody
public String demo1() throws Exception {
asnycservice.hello();
return "ok!";
}
}
Effect, the user will wait on the page
At this time, we can use Springboot's asynchronous task, only need to open two annotations, purpose, if we are sending emails, we must first tell the user that it is sending, the background can process data.
That's it,
effect
mail,
simple text mail,
import dependency
<!-- 邮箱的-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
L yml
#邮箱的配置
spring:
mail:
host: smtp.163.com
username: ************@163.com
password: ****************
protocol: smtp
default-encoding: UTF-8
Write in the test class. The second
effect is
to send unusual emails!
Effects,
colors and pictures are here!
Timed tasks,
critical interfaces
TaskScheduler task scheduler
TackExecutor task executor
, add comments to the main program
Write in the business layer
package com.jj.demo.service;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;
@Service
public class Schedulingservice {
//cron 表达式
//秒 分 时 日 月 周几
@Scheduled(cron = "0 38 16 * * ?")
public void helo(){
System.out.println("哈哈哈哈哈");
}
}
The effect of
Baidu's a cron expression