zl程序教程

您现在的位置是:首页 >  后端

当前栏目

java spring boot [email protected]编程语言

JAVASpringBoot编程语言 &# email 160 protected
2023-06-13 09:11:50 时间

java spring boot [email protected]

ps:我这里要说明下 这个异步是多线程 所以要考虑线程安全 变量共享的问题

1 首先开启类 

@EnableAsync //开启异步调用



2 直接方法前面加
@Async 就可以异步了
package com.example.demo2122; 

import org.springframework.scheduling.annotation.Async; 

import org.springframework.scheduling.annotation.Scheduled; 

import org.springframework.stereotype.Component; 

import org.springframework.web.bind.annotation.GetMapping; 

import org.springframework.web.bind.annotation.RequestParam; 

import org.springframework.web.bind.annotation.RestController; 

import javax.annotation.Resource; 

import java.util.*; 

import java.util.stream.IntStream; 

import org.springframework.scheduling.annotation.Async; 

import org.springframework.stereotype.Service; 

@RestController 

@Component 

public class HelloControl { 

 @GetMapping("/hello") 

 public String hello(@RequestParam(value = "name", defaultValue = "World") String name) { 

 System.out.println("####IndexController#### 1"); 

 this.sendSms(); 

 System.out.println("####IndexController#### 3"); 

 return "success"; 


原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/18954.html

cjava