# ExecutorService 异步线程池

[线程池 ExecutorService 的使用例子](https://blog.csdn.net/xiaojin21cen/article/details/81810534)

[Java多线程-Callable的Future返回值的使用](https://www.cnblogs.com/syp172654682/p/9788051.html)

[ExecutorService](https://www.jianshu.com/p/ff42d9aad56c)

```java
@RestController
@RequestMapping("/hello")
public class HelloController {

	private ExecutorService service = Executors.newFixedThreadPool(10);

    @GetMapping
    public String hello() {
        service.execute(new Runnable() {
    
            @Override
            public void run() {
                try {
                    TimeUnit.SECONDS.sleep(3);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
    
                System.out.println("我醒了");
            }
        });
    
        return "hello world";
    }
}
```

实例理解:

会先返回"hello world", 3秒钟后控制台输出"我醒了"


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiaoxiami.gitbook.io/java/executorservice-xian-cheng-chi.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
