-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0966152
commit 02e8b02
Showing
5 changed files
with
38 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
core/src/main/java/cn/edu/tsinghua/iot/benchmark/utils/NamedThreadFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cn.edu.tsinghua.iot.benchmark.utils; | ||
|
||
import java.util.concurrent.Executors; | ||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public class NamedThreadFactory implements ThreadFactory { | ||
private final String poolName; | ||
private final AtomicInteger count = new AtomicInteger(1); | ||
private final ThreadFactory threadFactory; | ||
|
||
public NamedThreadFactory(String name) { | ||
this.poolName = name; | ||
this.threadFactory = Executors.defaultThreadFactory(); | ||
} | ||
|
||
private String getThreadName() { | ||
return poolName + "-thread-" + String.valueOf(count.getAndIncrement()); | ||
} | ||
|
||
@Override | ||
public Thread newThread(Runnable r) { | ||
Thread thread = threadFactory.newThread(r); | ||
thread.setName(getThreadName()); | ||
return thread; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters