Class TtlExecutors
- wrap/check/unwrap methods for TTL wrapper of jdk executors(
Executor
,ExecutorService
,ScheduledExecutorService
). - wrap/check/unwrap methods for disable Inheritable wrapper of
ThreadFactory
. - wrap/check/unwrap methods for
TtlRunnableUnwrapComparator
wrapper ofPriorityBlockingQueue
.
Note:
- all method is
null
-safe. for wrap/unwrap methods when input parameter isnull
, returnnull
. for check methods when input parameter isnull
, returnfalse
. - skip wrap/decoration thread pool/
executor
(aka. just return inputexecutor
) when ttl agent is loaded, Or when inputexecutor
is already wrapped/decorated.
- Since:
- 0.9.0
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic ThreadFactory
Wrapper ofExecutors.defaultThreadFactory()
, disable inheritable.static ThreadFactory
getDisableInheritableThreadFactory
(ThreadFactory threadFactory) Wrapper ofThreadFactory
, disable inheritable.static Executor
getTtlExecutor
(Executor executor) TransmittableThreadLocal
Wrapper ofExecutor
, transmit theTransmittableThreadLocal
from the task submit time ofRunnable
to the execution time ofRunnable
.static ExecutorService
getTtlExecutorService
(ExecutorService executorService) TransmittableThreadLocal
Wrapper ofExecutorService
, transmit theTransmittableThreadLocal
from the task submit time ofRunnable
orCallable
to the execution time ofRunnable
orCallable
.static Comparator<Runnable>
getTtlRunnableUnwrapComparator
(Comparator<Runnable> comparator) Wrapper ofComparator<Runnable>
which unwrapTtlRunnable
before compare, akaTtlRunnableUnwrapComparator
.static Comparator<Runnable>
TtlRunnableUnwrapComparator
that comparesComparable
objects.static ScheduledExecutorService
getTtlScheduledExecutorService
(ScheduledExecutorService scheduledExecutorService) TransmittableThreadLocal
Wrapper ofScheduledExecutorService
, transmit theTransmittableThreadLocal
from the task submit time ofRunnable
orCallable
to the execution time ofRunnable
orCallable
.static boolean
isDisableInheritableThreadFactory
(ThreadFactory threadFactory) check theThreadFactory
isDisableInheritableThreadFactory
or not.static boolean
isTtlRunnableUnwrapComparator
(Comparator<Runnable> comparator) check theComparator<Runnable>
is a wrapperTtlRunnableUnwrapComparator
or not.static <T extends Executor>
booleanisTtlWrapper
(T executor) check the executor is a TTL executor wrapper or not.static Comparator<Runnable>
unwrap
(Comparator<Runnable> comparator) UnwrapTtlRunnableUnwrapComparator
to the original/underneathComparator<Runnable>
.static ThreadFactory
unwrap
(ThreadFactory threadFactory) UnwrapDisableInheritableThreadFactory
to the original/underneath one.static <T extends Executor>
Tunwrap
(T executor) Unwrap TTL executor wrapper to the original/underneath one.
-
Method Details
-
getTtlExecutor
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static Executor getTtlExecutor(@Nullable Executor executor) TransmittableThreadLocal
Wrapper ofExecutor
, transmit theTransmittableThreadLocal
from the task submit time ofRunnable
to the execution time ofRunnable
.NOTE: sine v2.12.0 the idempotency of return wrapped Executor is changed to true, so the wrapped Executor can be cooperated with the usage of "Decorate Runnable and Callable".
About idempotency: if is idempotent, it's allowed to submit the
TtlRunnable
/TtlCallable
to the wrapped Executor; otherwise throwIllegalStateException
.- Parameters:
executor
- input Executor- Returns:
- wrapped Executor
- See Also:
-
getTtlExecutorService
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static ExecutorService getTtlExecutorService(@Nullable ExecutorService executorService) TransmittableThreadLocal
Wrapper ofExecutorService
, transmit theTransmittableThreadLocal
from the task submit time ofRunnable
orCallable
to the execution time ofRunnable
orCallable
.NOTE: sine v2.12.0 the idempotency of return wrapped ExecutorService is changed to true, so the wrapped ExecutorService can be cooperated with the usage of "Decorate Runnable and Callable".
About idempotency: if is idempotent, it's allowed to submit the
TtlRunnable
/TtlCallable
to the wrapped ExecutorService; otherwise throwIllegalStateException
.- Parameters:
executorService
- input ExecutorService- Returns:
- wrapped ExecutorService
- See Also:
-
getTtlScheduledExecutorService
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static ScheduledExecutorService getTtlScheduledExecutorService(@Nullable ScheduledExecutorService scheduledExecutorService) TransmittableThreadLocal
Wrapper ofScheduledExecutorService
, transmit theTransmittableThreadLocal
from the task submit time ofRunnable
orCallable
to the execution time ofRunnable
orCallable
.NOTE: sine v2.12.0 the idempotency of return wrapped ScheduledExecutorService is changed to true, so the wrapped ScheduledExecutorService can be cooperated with the usage of "Decorate Runnable and Callable".
About idempotency: if is idempotent, it's allowed to submit the
TtlRunnable
/TtlCallable
to the wrapped ScheduledExecutorService; otherwise throwIllegalStateException
.- Parameters:
scheduledExecutorService
- input scheduledExecutorService- Returns:
- wrapped scheduledExecutorService
- See Also:
-
isTtlWrapper
check the executor is a TTL executor wrapper or not.if the parameter executor is TTL wrapper, return
true
, otherwisefalse
.NOTE: if input executor is
null
, returnfalse
.- Type Parameters:
T
- Executor type- Parameters:
executor
- input executor- Since:
- 2.8.0
- See Also:
-
unwrap
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static <T extends Executor> T unwrap(@Nullable T executor) Unwrap TTL executor wrapper to the original/underneath one.if the parameter executor is TTL wrapper, return the original/underneath executor; otherwise, just return the input parameter executor.
NOTE: if input executor is
null
, returnnull
.- Type Parameters:
T
- Executor type- Parameters:
executor
- input executor- Since:
- 2.8.0
- See Also:
-
getDisableInheritableThreadFactory
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static ThreadFactory getDisableInheritableThreadFactory(@Nullable ThreadFactory threadFactory) Wrapper ofThreadFactory
, disable inheritable.- Parameters:
threadFactory
- input thread factory- Since:
- 2.10.0
- See Also:
-
getDefaultDisableInheritableThreadFactory
Wrapper ofExecutors.defaultThreadFactory()
, disable inheritable. -
isDisableInheritableThreadFactory
check theThreadFactory
isDisableInheritableThreadFactory
or not. -
unwrap
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static ThreadFactory unwrap(@Nullable ThreadFactory threadFactory) UnwrapDisableInheritableThreadFactory
to the original/underneath one. -
getTtlRunnableUnwrapComparator
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static Comparator<Runnable> getTtlRunnableUnwrapComparator(@Nullable Comparator<Runnable> comparator) Wrapper ofComparator<Runnable>
which unwrapTtlRunnable
before compare, akaTtlRunnableUnwrapComparator
.Prepared for
comparator
parameter of constructorPriorityBlockingQueue(int, Comparator)
.PriorityBlockingQueue
can be used by constructorThreadPoolExecutor(int, int, long, java.util.concurrent.TimeUnit, java.util.concurrent.BlockingQueue)
.- Parameters:
comparator
- input comparator- Returns:
- wrapped comparator
- Since:
- 2.12.3
- See Also:
-
getTtlRunnableUnwrapComparatorForComparableRunnable
TtlRunnableUnwrapComparator
that comparesComparable
objects.- Since:
- 2.12.3
- See Also:
-
isTtlRunnableUnwrapComparator
check theComparator<Runnable>
is a wrapperTtlRunnableUnwrapComparator
or not.- Since:
- 2.12.3
- See Also:
-
unwrap
@Nullable @Contract(value="null -> null; !null -> !null", pure=true) public static Comparator<Runnable> unwrap(@Nullable Comparator<Runnable> comparator) UnwrapTtlRunnableUnwrapComparator
to the original/underneathComparator<Runnable>
.
-