Top Description Inners Fields Constructors Methods
net.sf.ehcache.constructs.nonstop.util

public Class CountingThreadFactory

extends Object
implements ThreadFactory
Class Inheritance
All Implemented Interfaces
java.util.concurrent.ThreadFactory
Imports
java.util.concurrent.ThreadFactory, java.util.concurrent.atomic.AtomicInteger

A custom ThreadFactory that maintains a count of how many threads this factory has created
Author
Abhishek Sanoujam

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
CountingThreadFactory.RunnableWithLifeCycle

Runnable which also fires lifecycle events

Field Summary

Modifier and TypeField and Description
private final ThreadFactory
private final AtomicInteger

Constructor Summary

AccessConstructor and Description
public
CountingThreadFactory(ThreadFactory
the actual factory
actualFactory
)

Constructor accepting the actual thread factory that will create the threads

Method Summary

Modifier and TypeMethod and Description
public int

Returns:

Returns the number of threads this factory has created and currently alive
getNumberOfThreads
()

Returns the number of threads this factory has created and currently alive

public Thread
newThread(Runnable
a runnable to be executed by new thread instance
r
)

Implements java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.
private void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualFactoryback to summary
private final ThreadFactory actualFactory
countback to summary
private final AtomicInteger count

Constructor Detail

CountingThreadFactoryback to summary
public CountingThreadFactory(ThreadFactory actualFactory)

Constructor accepting the actual thread factory that will create the threads

Parameters
actualFactory:ThreadFactory

the actual factory

Method Detail

getNumberOfThreadsback to summary
public int getNumberOfThreads()

Returns the number of threads this factory has created and currently alive

Returns:int

Returns the number of threads this factory has created and currently alive

newThreadback to summary
public Thread newThread(Runnable r)

Implements java.util.concurrent.ThreadFactory.newThread.

Doc from java.util.concurrent.ThreadFactory.newThread.

Constructs a new unstarted Thread to run the given runnable.

Parameters
r:Runnable

a runnable to be executed by new thread instance

Returns:Thread

constructed thread, or null if the request to create a thread is rejected

threadExecutionCompleteback to summary
private void threadExecutionComplete()
net.sf.ehcache.constructs.nonstop.util back to summary

private Class CountingThreadFactory.RunnableWithLifeCycle

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • net.sf.ehcache.constructs.nonstop.util.CountingThreadFactory.RunnableWithLifeCycle
All Implemented Interfaces
java.lang.Runnable

Runnable which also fires lifecycle events
Author
Abhishek Sanoujam

Field Summary

Modifier and TypeField and Description
private final Runnable
private final CountingThreadFactory

Constructor Summary

AccessConstructor and Description
public
RunnableWithLifeCycle(CountingThreadFactory countingThreadFactory, Runnable actualRunnable)

Constructor accepting a CountingThreadFactory and the actual runnable

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

actualRunnableback to summary
private final Runnable actualRunnable
countingThreadFactoryback to summary
private final CountingThreadFactory countingThreadFactory

Constructor Detail

RunnableWithLifeCycleback to summary
public RunnableWithLifeCycle(CountingThreadFactory countingThreadFactory, Runnable actualRunnable)

Constructor accepting a CountingThreadFactory and the actual runnable

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.