TaskExecutor 异步线程池
package com.boot.study.controller;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.task.TaskExecutor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.boot.study.service.AsyncService;
@RestController
@RequestMapping("/hello")
public class HelloController {
@Autowired
private TaskExecutor taskExecutor;
@GetMapping("/map")
public Map<String, Object> map() {
Map<String, Object> map = new HashMap<>();
map.put("name", "revin");
map.put("age", 18);
taskExecutor.execute(new Runnable() {
@Override
public void run() {
try {
TimeUnit.SECONDS.sleep(3);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("我醒了22");
}
});
return map;
}
}
Last updated