@RestController @Slf4j public class Thread04 { @Autowired private OrderManage orderManage; @GetMapping("addOrder") public String addOrder(){ log.info("1"); //异步处理 orderManage.asyncLog(); log.info("3"); log.info(Thread.currentThread().getName()+"执行结束"); return "5"; } }
OrderManage 类
package boot.thread; import lombok.extern.slf4j.Slf4j; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @Component @Slf4j public class OrderManage { @Async//异步注解,方法会异步执行 public void asyncLog(){ try { Thread.sleep(3000); } catch (InterruptedException e) { throw new RuntimeException(e); } log.info(Thread.currentThread().getName()+"--2"); } }
标签:info,异步,log,import,注解,Async,public From: https://www.cnblogs.com/ixtao/p/17455487.html