public final class InstrumentedExecutors extends Object
InstrumentedExecutorService,
InstrumentedScheduledExecutorService, and InstrumentedThreadFactory
classes defined in this package. This class supports the following kinds of methods:
InstrumentedExecutorService
set up with commonly useful configuration settings.
InstrumentedScheduledExecutorService
set up with commonly useful configuration settings.
InstrumentedThreadFactory
that sets newly created threads to a known state.
Executors| Modifier and Type | Method and Description |
|---|---|
static InstrumentedThreadFactory |
defaultThreadFactory(MetricRegistry registry)
Returns an instrumented default thread factory used to create new threads.
|
static InstrumentedThreadFactory |
defaultThreadFactory(MetricRegistry registry,
String name)
Returns an instrumented default thread factory used to create new threads.
|
static InstrumentedExecutorService |
newCachedThreadPool(MetricRegistry registry)
Creates an instrumented thread pool that creates new threads as needed, but
will reuse previously constructed threads when they are
available.
|
static InstrumentedExecutorService |
newCachedThreadPool(MetricRegistry registry,
String name)
Creates an instrumented thread pool that creates new threads as needed, but
will reuse previously constructed threads when they are
available.
|
static InstrumentedExecutorService |
newCachedThreadPool(ThreadFactory threadFactory,
MetricRegistry registry)
Creates an instrumented thread pool that creates new threads as needed, but
will reuse previously constructed threads when they are
available, and uses the provided
ThreadFactory to create new threads when needed.
|
static InstrumentedExecutorService |
newCachedThreadPool(ThreadFactory threadFactory,
MetricRegistry registry,
String name)
Creates an instrumented thread pool that creates new threads as needed, but
will reuse previously constructed threads when they are
available, and uses the provided
ThreadFactory to create new threads when needed.
|
static InstrumentedExecutorService |
newFixedThreadPool(int nThreads,
MetricRegistry registry)
Creates an instrumented thread pool that reuses a fixed number of threads
operating off a shared unbounded queue.
|
static InstrumentedExecutorService |
newFixedThreadPool(int nThreads,
MetricRegistry registry,
String name)
Creates an instrumented thread pool that reuses a fixed number of threads
operating off a shared unbounded queue.
|
static InstrumentedExecutorService |
newFixedThreadPool(int nThreads,
ThreadFactory threadFactory,
MetricRegistry registry)
Creates a thread pool that reuses a fixed number of threads
operating off a shared unbounded queue, using the provided
ThreadFactory to create new threads when needed.
|
static InstrumentedExecutorService |
newFixedThreadPool(int nThreads,
ThreadFactory threadFactory,
MetricRegistry registry,
String name)
Creates an instrumented thread pool that reuses a fixed number of threads
operating off a shared unbounded queue, using the provided
ThreadFactory to create new threads when needed.
|
static InstrumentedScheduledExecutorService |
newScheduledThreadPool(int corePoolSize,
MetricRegistry registry)
Creates an instrumented thread pool that can schedule commands to run after a
given delay, or to execute periodically.
|
static InstrumentedScheduledExecutorService |
newScheduledThreadPool(int corePoolSize,
MetricRegistry registry,
String name)
Creates an instrumented thread pool that can schedule commands to run after a
given delay, or to execute periodically.
|
static InstrumentedScheduledExecutorService |
newScheduledThreadPool(int corePoolSize,
ThreadFactory threadFactory,
MetricRegistry registry)
Creates an instrumented thread pool that can schedule commands to run after a
given delay, or to execute periodically.
|
static InstrumentedScheduledExecutorService |
newScheduledThreadPool(int corePoolSize,
ThreadFactory threadFactory,
MetricRegistry registry,
String name)
Creates an instrumented thread pool that can schedule commands to run after a
given delay, or to execute periodically.
|
static InstrumentedExecutorService |
newSingleThreadExecutor(MetricRegistry registry)
Creates an Executor that uses a single worker thread operating
off an unbounded queue.
|
static InstrumentedExecutorService |
newSingleThreadExecutor(MetricRegistry registry,
String name)
Creates an InstrumentedExecutor that uses a single worker thread operating
off an unbounded queue.
|
static InstrumentedExecutorService |
newSingleThreadExecutor(ThreadFactory threadFactory,
MetricRegistry registry)
Creates an InstrumentedExecutor that uses a single worker thread operating
off an unbounded queue, and uses the provided ThreadFactory to
create a new thread when needed.
|
static InstrumentedExecutorService |
newSingleThreadExecutor(ThreadFactory threadFactory,
MetricRegistry registry,
String name)
Creates an InstrumentedExecutor that uses a single worker thread operating
off an unbounded queue, and uses the provided ThreadFactory to
create a new thread when needed.
|
static InstrumentedScheduledExecutorService |
newSingleThreadScheduledExecutor(MetricRegistry registry)
Creates a single-threaded instrumented executor that can schedule commands
to run after a given delay, or to execute periodically.
|
static InstrumentedScheduledExecutorService |
newSingleThreadScheduledExecutor(MetricRegistry registry,
String name)
Creates a single-threaded instrumented executor that can schedule commands
to run after a given delay, or to execute periodically.
|
static InstrumentedScheduledExecutorService |
newSingleThreadScheduledExecutor(ThreadFactory threadFactory,
MetricRegistry registry)
Creates a single-threaded instrumented executor that can schedule commands
to run after a given delay, or to execute periodically.
|
static InstrumentedScheduledExecutorService |
newSingleThreadScheduledExecutor(ThreadFactory threadFactory,
MetricRegistry registry,
String name)
Creates a single-threaded instrumented executor that can schedule commands
to run after a given delay, or to execute periodically.
|
static InstrumentedThreadFactory |
privilegedThreadFactory(MetricRegistry registry)
Returns an instrumented thread factory used to create new threads that
have the same permissions as the current thread.
|
static InstrumentedThreadFactory |
privilegedThreadFactory(MetricRegistry registry,
String name)
Returns an instrumented thread factory used to create new threads that
have the same permissions as the current thread.
|
public static InstrumentedExecutorService newFixedThreadPool(int nThreads, MetricRegistry registry, String name)
nThreads threads will be active processing tasks.
If additional tasks are submitted when all threads are active,
they will wait in the queue until a thread is available.
If any thread terminates due to a failure during execution
prior to shutdown, a new one will take its place if needed to
execute subsequent tasks. The threads in the pool will exist
until it is explicitly shutdown.nThreads - the number of threads in the poolregistry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).IllegalArgumentException - if nThreads <= 0Executors.newFixedThreadPool(int)public static InstrumentedExecutorService newFixedThreadPool(int nThreads, MetricRegistry registry)
nThreads threads will be active processing tasks.
If additional tasks are submitted when all threads are active,
they will wait in the queue until a thread is available.
If any thread terminates due to a failure during execution
prior to shutdown, a new one will take its place if needed to
execute subsequent tasks. The threads in the pool will exist
until it is explicitly shutdown.nThreads - the number of threads in the poolregistry - the MetricRegistry that will contain the metrics.IllegalArgumentException - if nThreads <= 0Executors.newFixedThreadPool(int)public static InstrumentedExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory, MetricRegistry registry, String name)
nThreads threads will be active processing
tasks. If additional tasks are submitted when all threads are
active, they will wait in the queue until a thread is
available. If any thread terminates due to a failure during
execution prior to shutdown, a new one will take its place if
needed to execute subsequent tasks. The threads in the pool will
exist until it is explicitly shutdown.nThreads - the number of threads in the poolthreadFactory - the factory to use when creating new threadsregistry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).NullPointerException - if threadFactory is nullIllegalArgumentException - if nThreads <= 0Executors.newFixedThreadPool(int, ThreadFactory)public static InstrumentedExecutorService newFixedThreadPool(int nThreads, ThreadFactory threadFactory, MetricRegistry registry)
nThreads threads will be active processing
tasks. If additional tasks are submitted when all threads are
active, they will wait in the queue until a thread is
available. If any thread terminates due to a failure during
execution prior to shutdown, a new one will take its place if
needed to execute subsequent tasks. The threads in the pool will
exist until it is explicitly shutdown.nThreads - the number of threads in the poolthreadFactory - the factory to use when creating new threadsregistry - the MetricRegistry that will contain the metrics.NullPointerException - if threadFactory is nullIllegalArgumentException - if nThreads <= 0Executors.newFixedThreadPool(int, ThreadFactory)public static InstrumentedExecutorService newSingleThreadExecutor(MetricRegistry registry, String name)
newFixedThreadPool(1) the returned executor is
guaranteed not to be reconfigurable to use additional threads.registry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).Executors.newSingleThreadExecutor()public static InstrumentedExecutorService newSingleThreadExecutor(MetricRegistry registry)
newFixedThreadPool(1) the returned executor is
guaranteed not to be reconfigurable to use additional threads.registry - the MetricRegistry that will contain the metrics.Executors.newSingleThreadExecutor()public static InstrumentedExecutorService newSingleThreadExecutor(ThreadFactory threadFactory, MetricRegistry registry, String name)
newFixedThreadPool(1, threadFactory) the
returned executor is guaranteed not to be reconfigurable to use
additional threads.threadFactory - the factory to use when creating new threadsregistry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).NullPointerException - if threadFactory is nullExecutors.newSingleThreadExecutor(ThreadFactory)public static InstrumentedExecutorService newSingleThreadExecutor(ThreadFactory threadFactory, MetricRegistry registry)
newFixedThreadPool(1, threadFactory) the
returned executor is guaranteed not to be reconfigurable to use
additional threads.threadFactory - the factory to use when creating new threadsregistry - the MetricRegistry that will contain the metrics.NullPointerException - if threadFactory is nullExecutors.newSingleThreadExecutor(ThreadFactory)public static InstrumentedExecutorService newCachedThreadPool(MetricRegistry registry, String name)
execute will reuse previously constructed
threads if available. If no existing thread is available, a new
thread will be created and added to the pool. Threads that have
not been used for sixty seconds are terminated and removed from
the cache. Thus, a pool that remains idle for long enough will
not consume any resource. Note that pools with similar
properties but different details (for example, timeout parameters)
may be created using ThreadPoolExecutor constructors.registry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).Executors.newCachedThreadPool()public static InstrumentedExecutorService newCachedThreadPool(MetricRegistry registry)
execute will reuse previously constructed
threads if available. If no existing thread is available, a new
thread will be created and added to the pool. Threads that have
not been used for sixty seconds are terminated and removed from
the cache. Thus, a pool that remains idle for long enough will
not consume any resource. Note that pools with similar
properties but different details (for example, timeout parameters)
may be created using ThreadPoolExecutor constructors.registry - the MetricRegistry that will contain the metrics.Executors.newCachedThreadPool()public static InstrumentedExecutorService newCachedThreadPool(ThreadFactory threadFactory, MetricRegistry registry, String name)
threadFactory - the factory to use when creating new threadsregistry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).NullPointerException - if threadFactory is nullExecutors.newCachedThreadPool(ThreadFactory)public static InstrumentedExecutorService newCachedThreadPool(ThreadFactory threadFactory, MetricRegistry registry)
threadFactory - the factory to use when creating new threadsregistry - the MetricRegistry that will contain the metrics.NullPointerException - if threadFactory is nullExecutors.newCachedThreadPool(ThreadFactory)public static InstrumentedScheduledExecutorService newSingleThreadScheduledExecutor(MetricRegistry registry, String name)
newScheduledThreadPool(1) the returned executor is
guaranteed not to be reconfigurable to use additional threads.registry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).Executors.newSingleThreadScheduledExecutor()public static InstrumentedScheduledExecutorService newSingleThreadScheduledExecutor(MetricRegistry registry)
newScheduledThreadPool(1) the returned executor is
guaranteed not to be reconfigurable to use additional threads.registry - the MetricRegistry that will contain the metrics.Executors.newSingleThreadScheduledExecutor()public static InstrumentedScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory, MetricRegistry registry, String name)
newScheduledThreadPool(1, threadFactory)
the returned executor is guaranteed not to be reconfigurable to
use additional threads.threadFactory - the factory to use when creating new threadsregistry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).NullPointerException - if threadFactory is nullExecutors.newSingleThreadExecutor(ThreadFactory)public static InstrumentedScheduledExecutorService newSingleThreadScheduledExecutor(ThreadFactory threadFactory, MetricRegistry registry)
newScheduledThreadPool(1, threadFactory)
the returned executor is guaranteed not to be reconfigurable to
use additional threads.threadFactory - the factory to use when creating new threadsregistry - the MetricRegistry that will contain the metrics.NullPointerException - if threadFactory is nullExecutors.newSingleThreadExecutor(ThreadFactory)public static InstrumentedScheduledExecutorService newScheduledThreadPool(int corePoolSize, MetricRegistry registry, String name)
corePoolSize - the number of threads to keep in the pool,
even if they are idleregistry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).IllegalArgumentException - if corePoolSize < 0Executors.newScheduledThreadPool(int)public static InstrumentedScheduledExecutorService newScheduledThreadPool(int corePoolSize, MetricRegistry registry)
corePoolSize - the number of threads to keep in the pool,
even if they are idleregistry - the MetricRegistry that will contain the metrics.IllegalArgumentException - if corePoolSize < 0Executors.newScheduledThreadPool(int)public static InstrumentedScheduledExecutorService newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory, MetricRegistry registry, String name)
corePoolSize - the number of threads to keep in the pool,
even if they are idlethreadFactory - the factory to use when the executor
creates a new threadregistry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).IllegalArgumentException - if corePoolSize < 0NullPointerException - if threadFactory is nullExecutors.newScheduledThreadPool(int, ThreadFactory)public static InstrumentedScheduledExecutorService newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory, MetricRegistry registry)
corePoolSize - the number of threads to keep in the pool, even if they are idlethreadFactory - the factory to use when the executor creates a new threadregistry - the MetricRegistry that will contain the metrics.IllegalArgumentException - if corePoolSize < 0NullPointerException - if threadFactory is nullExecutors.newScheduledThreadPool(int, ThreadFactory)public static InstrumentedThreadFactory defaultThreadFactory(MetricRegistry registry, String name)
ThreadGroup. If there is a SecurityManager, it uses the group of System.getSecurityManager(), else the group of the thread
invoking this defaultThreadFactory method. Each new
thread is created as a non-daemon thread with priority set to
the smaller of Thread.NORM_PRIORITY and the maximum
priority permitted in the thread group. New threads have names
accessible via Thread.getName() of
pool-N-thread-M, where N is the sequence
number of this factory, and M is the sequence number
of the thread created by this factory.registry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).Executors.defaultThreadFactory()public static InstrumentedThreadFactory defaultThreadFactory(MetricRegistry registry)
ThreadGroup. If there is a SecurityManager, it uses the group of System.getSecurityManager(), else the group of the thread
invoking this defaultThreadFactory method. Each new
thread is created as a non-daemon thread with priority set to
the smaller of Thread.NORM_PRIORITY and the maximum
priority permitted in the thread group. New threads have names
accessible via Thread.getName() of
pool-N-thread-M, where N is the sequence
number of this factory, and M is the sequence number
of the thread created by this factory.registry - the MetricRegistry that will contain the metrics.Executors.defaultThreadFactory()public static InstrumentedThreadFactory privilegedThreadFactory(MetricRegistry registry, String name)
This factory creates threads with the same settings as Executors.defaultThreadFactory(), additionally setting the
AccessControlContext and contextClassLoader of new threads to
be the same as the thread invoking this
privilegedThreadFactory method. A new
privilegedThreadFactory can be created within an
AccessController.doPrivileged
action setting the current thread's access control context to
create threads with the selected permission settings holding
within that action.
Note that while tasks running within such threads will have
the same access control and class loader settings as the
current thread, they need not have the same ThreadLocal or InheritableThreadLocal values. If necessary,
particular values of thread locals can be set or reset before
any task runs in ThreadPoolExecutor subclasses using
ThreadPoolExecutor.beforeExecute(Thread, Runnable).
Also, if it is necessary to initialize worker threads to have
the same InheritableThreadLocal settings as some other
designated thread, you can create a custom ThreadFactory in
which that thread waits for and services requests to create
others that will inherit its values.
registry - the MetricRegistry that will contain the metrics.name - the (metrics) name for this executor service, see MetricRegistry.name(String, String...).AccessControlException - if the current access control
context does not have permission to both get and set context
class loaderExecutors.privilegedThreadFactory()public static InstrumentedThreadFactory privilegedThreadFactory(MetricRegistry registry)
This factory creates threads with the same settings as Executors.defaultThreadFactory(), additionally setting the
AccessControlContext and contextClassLoader of new threads to
be the same as the thread invoking this
privilegedThreadFactory method. A new
privilegedThreadFactory can be created within an
AccessController.doPrivileged
action setting the current thread's access control context to
create threads with the selected permission settings holding
within that action.
Note that while tasks running within such threads will have
the same access control and class loader settings as the
current thread, they need not have the same ThreadLocal or InheritableThreadLocal values. If necessary,
particular values of thread locals can be set or reset before
any task runs in ThreadPoolExecutor subclasses using
ThreadPoolExecutor.beforeExecute(Thread, Runnable).
Also, if it is necessary to initialize worker threads to have
the same InheritableThreadLocal settings as some other
designated thread, you can create a custom ThreadFactory in
which that thread waits for and services requests to create
others that will inherit its values.
registry - the MetricRegistry that will contain the metrics.AccessControlException - if the current access control
context does not have permission to both get and set context
class loaderExecutors.privilegedThreadFactory()Copyright © 2021. All rights reserved.