MCPcopy Create free account
hub / github.com/belaban/JGroups / DefaultThreadFactory

Class DefaultThreadFactory

src/org/jgroups/util/DefaultThreadFactory.java:19–129  ·  view source on GitHub ↗

Thread factory mainly responsible for naming of threads. Can be replaced by user. If use_numbering is set, a thread THREAD will be called THREAD-1, THREAD-2, and so on. If a pattern has been set (through setPattern()), then the cluster name and local address will also be added, e.g. THREAD-5,MyCl

Source from the content-addressed store, hash-verified

17 * @author Bela Ban
18 */
19public class DefaultThreadFactory implements ThreadFactory {
20 protected final String baseName;
21 protected final boolean createDaemons;
22 protected final boolean use_numbering;
23 protected final AtomicInteger counter=new AtomicInteger(); // if numbering is enabled
24 protected boolean includeClusterName;
25 protected String clusterName;
26 protected boolean includeLocalAddress;
27 protected String address;
28 protected boolean use_vthreads; // use fibers instead of threads (requires Java 15)
29 protected Log log;
30
31
32 public DefaultThreadFactory(String base_name, boolean createDaemons) {
33 this(base_name, createDaemons, false);
34 }
35
36 public DefaultThreadFactory(String base_name, boolean createDaemons, boolean use_numbering) {
37 this.baseName=base_name;
38 this.createDaemons=createDaemons;
39 this.use_numbering=use_numbering;
40 }
41
42 public void setPattern(String pattern) {
43 if(pattern != null) {
44 includeClusterName=pattern.contains("c");
45 includeLocalAddress=pattern.contains("l");
46 }
47 }
48
49 public void setIncludeClusterName(boolean includeClusterName) {
50 this.includeClusterName=includeClusterName;
51 }
52
53 public void setClusterName(String channelName) {
54 clusterName=channelName;
55 }
56
57 public void setAddress(String address) {
58 this.address=address;
59 }
60
61 @Deprecated(forRemoval=true)
62 public boolean useFibers() {return useVirtualThreads();}
63 @Deprecated(forRemoval=true)
64 public <T extends DefaultThreadFactory> T useFibers(boolean f) {return useVirtualThreads(f);}
65 @Override
66 public boolean useVirtualThreads() {return use_vthreads;}
67 public <T extends DefaultThreadFactory> T useVirtualThreads(boolean f) {this.use_vthreads=f; return (T)this;}
68 public <T extends DefaultThreadFactory> T useVThreads(boolean f) {return useVirtualThreads(f);}
69 public <T extends DefaultThreadFactory> T log(Log l) {this.log=l; return (T)this;}
70
71 public Thread newThread(Runnable r, String name) {
72 return newThread(r, name, null, null);
73 }
74
75 public Thread newThread(Runnable r) {
76 return newThread(r, baseName, null, null);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…