1
0
mirror of https://github.com/Snailclimb/JavaGuide synced 2025-06-16 18:10:13 +08:00

Update java-concurrent-questions-03.md

(cherry picked from commit b909162f1518108abddf0a07fea0277009a868e5)
This commit is contained in:
paigeman 2023-06-09 19:17:23 +08:00
parent ca05698e16
commit 78db34251a
No known key found for this signature in database
GPG Key ID: 5B81BFA20DA31317

View File

@ -367,16 +367,16 @@ public static class CallerRunsPolicy implements RejectedExecutionHandler {
给线程池里的线程命名通常有下面两种方式: 给线程池里的线程命名通常有下面两种方式:
**1、利用 guava 的 `ThreadFactoryBuilder` ** **1、利用 guava 的 `ThreadFactoryBuilder`**
```java ```java
ThreadFactory threadFactory = new ThreadFactoryBuilder() ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setNameFormat(threadNamePrefix + "-%d") .setNameFormat(threadNamePrefix + "-%d")
.setDaemon(true).build(); .setDaemon(true).build();
ExecutorService threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MINUTES, workQueue, threadFactory) ExecutorService threadPool = new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime, TimeUnit.MINUTES, workQueue, threadFactory);
``` ```
**2、自己实现 `ThreadFactor`。** **2、自己实现 `ThreadFactory`。**
```java ```java
import java.util.concurrent.Executors; import java.util.concurrent.Executors;