
在Service类声明一个注解@Async作为异步方法的标识
package com.qf.sping09test.service;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
@Service
public class AsyncService {
//告诉spring这是一个异步的方法
@Async
public void hello(){
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("数据正在处理...");
}
}
controller
package com.qf.sping09test.controller;
import com.qf.sping09test.service.AsyncService;
import org.sprin
订阅专栏 解锁全文
448

被折叠的 条评论
为什么被折叠?



