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:
parent
ca05698e16
commit
78db34251a
@ -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;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user