public class CountingThreadFactory
extends java.lang.Object
implements java.util.concurrent.ThreadFactory
ThreadFactory
that maintains a count of how many threads this factory has createdModifier and Type | Class and Description |
---|---|
private static class |
CountingThreadFactory.RunnableWithLifeCycle
Runnable which also fires lifecycle events
|
Modifier and Type | Field and Description |
---|---|
private java.util.concurrent.ThreadFactory |
actualFactory |
private java.util.concurrent.atomic.AtomicInteger |
count |
Constructor and Description |
---|
CountingThreadFactory(java.util.concurrent.ThreadFactory actualFactory)
Constructor accepting the actual thread factory that will create the threads
|
Modifier and Type | Method and Description |
---|---|
int |
getNumberOfThreads()
Returns the number of threads this factory has created and currently alive
|
java.lang.Thread |
newThread(java.lang.Runnable r) |
private void |
threadExecutionComplete() |
private final java.util.concurrent.atomic.AtomicInteger count
private final java.util.concurrent.ThreadFactory actualFactory
public CountingThreadFactory(java.util.concurrent.ThreadFactory actualFactory)
actualFactory
- the actual factorypublic java.lang.Thread newThread(java.lang.Runnable r)
newThread
in interface java.util.concurrent.ThreadFactory
public int getNumberOfThreads()
private void threadExecutionComplete()