目录
一、@EnableAsync
二、@Async
三、测试
一、@EnableAsync
二、@Async
@Service
public class IotLocationServiceImpl {
@Async
public void testA() {
try {
// 模拟阻塞
Thread.sleep(5000);
System.out.println("子线程执行完毕");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
三、测试
@Slf4j
@RestController
@RequestMapping("/test")
@RequiredArgsConstructor
public class TestController {
private final IotLocationServiceImpl iotLocationService;
@PostMapping("/test")
public Result<?> test() {
iotLocationService.testA();
return Result.success();
}
}