博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
springboot -- 方法异步设置
阅读量:3920 次
发布时间:2019-05-23

本文共 812 字,大约阅读时间需要 2 分钟。

1、主程序添加 @EnableAsync 开启异步

package com.example;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.scheduling.annotation.EnableAsync;@EnableAsync@SpringBootApplicationpublic class SpringbootDemoApplication {
public static void main(String[] args) {
SpringApplication.run(SpringbootDemoApplication.class, args); }}

2、在方法上添加 @Async

package com.example.service;import org.springframework.scheduling.annotation.Async;import org.springframework.stereotype.Service;@Servicepublic class TestService {
/* * 异步 */ @Async public void test(){
try {
Thread.sleep(3000); } catch (InterruptedException e) {
// TODO Auto-generated catch block e.printStackTrace(); } System.out.println("hello"); }}

转载地址:http://byern.baihongyu.com/

你可能感兴趣的文章
文件系统EXT3,EXT4和XFS的区别
查看>>
Centos7 udev
查看>>
Nmcli 网络管理命令行工具
查看>>
Linux IP地址配置
查看>>
firewalld和iptables
查看>>
SELinux
查看>>
nmcli双网卡绑定
查看>>
nmcli 网卡链路绑定team
查看>>
Linux下profile和bashrc四种的区别
查看>>
Linux文件查看指令整理
查看>>
Linux的三个时间参数
查看>>
Linux 用户ID和组ID
查看>>
Linux /etc/passwd文件
查看>>
Linux 档案搜寻指令整理
查看>>
RAID和LVM
查看>>
网关和路由的区别
查看>>
rc.local文件
查看>>
service命令
查看>>
服务器修改主机名
查看>>
Linux的ip指令
查看>>