异步任务
启动类
@MapperScan("com.topcheer.*.*.dao")
@SpringBootApplication
@EnableCaching
@EnableRabbit
@EnableAsync
public class Oss6Application {
public static void main(String[] args) {
SpringApplication.run(Oss6Application.class, args);
}
}Controller层
/**
* @author WGR
* @create 2019/10/12 -- 21:53
*/
@RestController
public class AsynController {
@Autowired
AsynService asyncService;
@GetMapping("/hello")
public String hello(){
asyncService.hello();
return "success";
}
}Service层
AJAX即“Asynchronous Javascript And XML”(异步JavaScript和XML),是指一种创建交互式网页应用的网页开发技术。它不是新的编程语言,而是一种使用现有标准的新方法,最大的优点是在不重新加载整个页面的情况下,可以与服务器交换数据并更新部分网页内容,不需要任何浏览器插件,但需要用户允许JavaScript在浏览器上执行。《php中级教程之ajax技术》带你快速
2114
/**
* @author WGR
* @create 2019/10/12 -- 21:52
*/
@Service
public class AsynService {
//告诉Spring这是一个异步方法
@Async
public void hello() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("处理数据中...");
}
}测试结果:
页面直接显示success,控制台过3秒显示处理数据中...
以上就是Springboot中异步任务的示例分析的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号