Class GovernedAffinityPinnedThreadFactory
- java.lang.Object
-
- org.sheinbergon.needle.concurrent.GovernedAffinityPinnedThreadFactory
-
- All Implemented Interfaces:
java.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory,java.util.concurrent.ThreadFactory,PinnedThreadFactory
public final class GovernedAffinityPinnedThreadFactory extends java.lang.Object implements PinnedThreadFactory
-
-
Constructor Summary
Constructors Constructor Description GovernedAffinityPinnedThreadFactory()BuildPinnedThreadinstances using the default process affinity for newly createdPinnedThreadinstances.GovernedAffinityPinnedThreadFactory(org.sheinbergon.needle.AffinityDescriptor affinityDescriptor)BuildPinnedThreadinstances using the givenAffinityDescriptorfor newly createdPinnedThreadinstances.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidalter(org.sheinbergon.needle.AffinityDescriptor affinityDescriptor, boolean affectGoverned)Safely returns the livePinnedThreadcount governed by this factory.intgoverned()Safely returns the livePinnedThreadcount governed by this factory.org.sheinbergon.needle.PinnedThreadnewThread(java.lang.Runnable r)Constructs a newPinnedThread.org.sheinbergon.needle.PinnedThread.ForkJoinWorkernewThread(java.util.concurrent.ForkJoinPool pool)
-
-
-
Constructor Detail
-
GovernedAffinityPinnedThreadFactory
public GovernedAffinityPinnedThreadFactory()
BuildPinnedThreadinstances using the default process affinity for newly createdPinnedThreadinstances.Note: you can set the affinity settings for both governed and future threads by calling
GovernedAffinityPinnedThreadFactory#alter(Consumer)beyond the instantiation of this factory
-
GovernedAffinityPinnedThreadFactory
public GovernedAffinityPinnedThreadFactory(@Nonnull org.sheinbergon.needle.AffinityDescriptor affinityDescriptor)BuildPinnedThreadinstances using the givenAffinityDescriptorfor newly createdPinnedThreadinstances.Note: you can set the affinity settings for both governed and future threads by calling
GovernedAffinityPinnedThreadFactory#alter(Consumer)beyond the instantiation of this factory- Parameters:
affinityDescriptor- The affinity descriptor to use for creating newPinnedThreadinstances
-
-
Method Detail
-
governed
public int governed()
Safely returns the livePinnedThreadcount governed by this factory.- Returns:
- the amount of
PinnedThreadinstances currently governed by this factory
-
alter
public void alter(@Nonnull org.sheinbergon.needle.AffinityDescriptor affinityDescriptor, boolean affectGoverned)Safely returns the livePinnedThreadcount governed by this factory.- Parameters:
affinityDescriptor- The affinity descriptor to use for creating newPinnedThreadinstancesaffectGoverned- Whether or not the provideAffinityDescriptorshould be applied to the currently governedPinnedThreadset
-
newThread
public org.sheinbergon.needle.PinnedThread newThread(@Nonnull java.lang.Runnable r)Description copied from interface:PinnedThreadFactoryConstructs a newPinnedThread.- Specified by:
newThreadin interfacePinnedThreadFactory- Specified by:
newThreadin interfacejava.util.concurrent.ThreadFactory- Parameters:
r- a runnable to be executed by new thread instance- Returns:
- instantiated
PinnedThread, ornullif the request to create a thread is rejected
-
newThread
public org.sheinbergon.needle.PinnedThread.ForkJoinWorker newThread(@Nonnull java.util.concurrent.ForkJoinPool pool)- Specified by:
newThreadin interfacejava.util.concurrent.ForkJoinPool.ForkJoinWorkerThreadFactory- Specified by:
newThreadin interfacePinnedThreadFactory- Parameters:
pool- the pool this pinned worker thread operates in- Returns:
- the pinned worker thread, or null if the implementation rejects its inception
-
-