package task.demo.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import task.demo.service.AsyncService; import javax.sound.midi.Soundbank;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter; @RestController
public class AsyncController {
@Autowired
AsyncService asyncService; @RequestMapping("/hello")
public Object hello() {
//@EnableAsync //注解方式开启异步支持
String date1 = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println(date1);
asyncService.hello();
String date2 = LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
System.out.println(date2);
return "success";
}
}
package task.demo.service;

import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service; @Service
public class AsyncService { @Async
public void hello() {
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("开始执行");
}
}

  

Java SpringBoot注解方式开启异步支持的更多相关文章

  1. JAVA配置&注解方式搭建简单的SpringMVC前后台交互系统

    前面两篇文章介绍了 基于XML方式搭建SpringMVC前后台交互系统的方法,博文链接如下: http://www.cnblogs.com/hunterCecil/p/8252060.html htt ...

  2. AOP - 2 实例(SpringBoot 注解方式)

    1.创建Spring Boot项目 创建一个Spring Boot 项目,然后pom中引入web 模块与AOP相关依赖. <dependency> <groupId>org.s ...

  3. springboot注解方式使用redis缓存

    引入依赖库 在pom中引入依赖库,如下 <dependency> <groupId>org.springframework.boot</groupId> <a ...

  4. mybatis+druid+springboot 注解方式配置多个数据源

    1\数据库配置 #test数据源 spring.datasource.test.url=jdbc:mysql:///db?useUnicode= spring.datasource.test.user ...

  5. Java SpringBoot Scheduled定时任务

    package task.demo.controller; import org.springframework.beans.factory.annotation.Autowired; import ...

  6. SpringBoot整合定时任务和异步任务处理 3节课

    1.SpringBoot定时任务schedule讲解   定时任务应用场景: 简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类        ...

  7. SpringBoot整合定时任务和异步任务处理

    SpringBoot定时任务schedule讲解 简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类 timer:配置比较麻烦,时间延后问题, ...

  8. 小D课堂 - 零基础入门SpringBoot2.X到实战_第10节 SpringBoot整合定时任务和异步任务处理_41、SpringBoot定时任务schedule讲解

    笔记 1.SpringBoot定时任务schedule讲解     简介:讲解什么是定时任务和常见定时任务区别 1.常见定时任务 Java自带的java.util.Timer类            ...

  9. datax开启hana支持以及dolphinscheduler开启datax任务

    datax开启hana支持以及dolphinscheduler开启datax任务 前面(@,@) 前段时间因为要做异构数据导入导出,所以搜了下,发现这类工具收费的居多,使用起来未必趁手~ 于是我找了下 ...

随机推荐

  1. 【转载】C#中List集合First和FirstOrDefault方法有何不同

    在C#的List集合中查找一个符合条件的元素,一般我们会用First方法或者FirstOrDefault方法来返回第一个符合条件的对象,First方法和FirstOrDefault的调用都是使用Lam ...

  2. 用Visual Studio 2015 编写 MASM 汇编程序(二)从头开发一个Win32汇编程序

    一,建立一个VC的控制台类型的空工程: 1,从VS菜单中选择“文件”->“新建”->“项目”. 2,在新建项目中选择:“Visual c++”->"Win32"- ...

  3. 利用.bat脚本使得可运行jar开机自动运行

    1.利用Elipse到处可运行的jar包 2.写.bat脚本[点此下载],相应目录自己根据需要修改即可 3.将此脚本放在"启动"文件夹中

  4. Python学习日记(三) 学习使用dict

    数据按类型可划分为: 不可变数据类型(可哈希):元祖.string.int.bool 可变数据类型(不可哈希):dict.list 集合本身是可变数据类型,元素是不可变数据类型 字典中的key必须是不 ...

  5. python(字符串函数)

    一.字符串函数 1.首字母大小写 capitalize() title() name = "xinfangshuo" print (name.capitalize()) print ...

  6. elk使用不足及弥补报警措施

    全部都是6.6.2版本,就这还是没有敢选太新的 场景:每个收集点部署filebeat收集响应日志,然后发送到logstash,logstash发送到elasticsearch,和file,这里插一句, ...

  7. openwrt使用3G拔号的实践笔记

    参照文档: https://soha.moe/post/make-4g-wifi-ap-with-openwrt.html 步骤: 1.安装必要的包: opkg update opkg install ...

  8. prometheus operator 部署

    prometheus operator 部署自定义记录 环境: k8s 1.11集群版本,kubeadm部署 docker 17.3.2版本 Centos 7系统 阿里云服务器 operator 源码 ...

  9. mysql 两张表字段模糊匹配--字符串拼接函数

    concat(A,B,C,...)  拼接字符串 例如concat('123','***','345')  =>123***345 SELECT concat( substr(t1.CODE, ...

  10. spring boot学习笔记(一)

    (翻译看个人意愿) 官方介绍: Spring Boot makes it easy to create stand-alone, production-grade Spring based Appli ...