-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COH-29642 - Provide a default ThreadFactory implemetation for named E…
…xecutors (merge ce/main -> ce/23.09 @ 107362) [git-p4: depot-paths = "//dev/coherence-ce/release/coherence-ce-v23.09/": change = 107363]
- Loading branch information
Showing
5 changed files
with
115 additions
and
20 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
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
56 changes: 56 additions & 0 deletions
56
...rrent/src/main/java/com/oracle/coherence/concurrent/executor/util/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,56 @@ | ||
/* | ||
* Copyright (c) 2024, Oracle and/or its affiliates. | ||
* | ||
* Licensed under the Universal Permissive License v 1.0 as shown at | ||
* https://oss.oracle.com/licenses/upl. | ||
*/ | ||
package com.oracle.coherence.concurrent.executor.util; | ||
|
||
import java.util.concurrent.ThreadFactory; | ||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
|
||
/** | ||
* A {@link ThreadFactory} implementation for used with {@code named} | ||
* {@code Executors}. Each new thread's name will be composed by using | ||
* the name of the executor service as the prefix and a monotonically | ||
* increasing integer as the suffix. | ||
* | ||
* @author rl 3.8.2024 | ||
* @since 15.1.1.0 | ||
*/ | ||
public class NamedThreadFactory | ||
implements ThreadFactory | ||
{ | ||
// ----- constructors --------------------------------------------------- | ||
|
||
/** | ||
* Constructs a new {@code NamedThreadFactory} for the specified | ||
* executor name. | ||
* | ||
* @param f_sName the executor name | ||
*/ | ||
public NamedThreadFactory(String f_sName) | ||
{ | ||
if (f_sName == null || f_sName.isEmpty()) | ||
{ | ||
throw new IllegalArgumentException("A name must be specified"); | ||
} | ||
|
||
this.f_sName = f_sName; | ||
} | ||
|
||
// ----- ThreadFactory interface ---------------------------------------- | ||
|
||
@Override | ||
public Thread newThread(Runnable r) | ||
{ | ||
return new Thread(r, "CES:" + f_sName + '-' + f_counter.incrementAndGet()); | ||
} | ||
|
||
// ----- data members --------------------------------------------------- | ||
|
||
protected final AtomicInteger f_counter = new AtomicInteger(); | ||
|
||
protected final String f_sName; | ||
} |