Class TtlExecutors
- java.lang.Object
-
- com.alibaba.ttl.threadpool.TtlExecutors
-
public final class TtlExecutors extends Object
Util methods for TTL wrapper of jdk executors.- Factory methods to get TTL wrapper from jdk executors.
- unwrap/check methods for TTL wrapper of jdk executors.
- wrap/unwrap/check methods to disable Inheritable for
ThreadFactory.
Note:
- all method is
null-safe, when inputexecutorparameter isnull, returnnull. - skip wrap/decoration thread pool/
executor(aka. just return inputexecutor) when ttl agent is loaded, Or when inputexecutoris already wrapped/decorated.
- Since:
- 0.9.0
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
Executor,ExecutorService,ThreadPoolExecutor,ScheduledThreadPoolExecutor,Executors,CompletionService,ExecutorCompletionService,ThreadFactory,Executors.defaultThreadFactory()
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static ThreadFactorygetDefaultDisableInheritableThreadFactory()Wrapper ofExecutors.defaultThreadFactory(), disable inheritable.static ThreadFactorygetDisableInheritableThreadFactory(ThreadFactory threadFactory)Wrapper ofThreadFactory, disable inheritable.static ExecutorgetTtlExecutor(Executor executor)TransmittableThreadLocalWrapper ofExecutor, transmit theTransmittableThreadLocalfrom the task submit time ofRunnableto the execution time ofRunnable.static ExecutorServicegetTtlExecutorService(ExecutorService executorService)TransmittableThreadLocalWrapper ofExecutorService, transmit theTransmittableThreadLocalfrom the task submit time ofRunnableorCallableto the execution time ofRunnableorCallable.static ScheduledExecutorServicegetTtlScheduledExecutorService(ScheduledExecutorService scheduledExecutorService)TransmittableThreadLocalWrapper ofScheduledExecutorService, transmit theTransmittableThreadLocalfrom the task submit time ofRunnableorCallableto the execution time ofRunnableorCallable.static booleanisDisableInheritableThreadFactory(ThreadFactory threadFactory)check theThreadFactoryisDisableInheritableThreadFactoryor not.static <T extends Executor>
booleanisTtlWrapper(T executor)check the executor is TTL wrapper executor or not.static ThreadFactoryunwrap(ThreadFactory threadFactory)UnwrapDisableInheritableThreadFactoryto the original/underneath one.static <T extends Executor>
Tunwrap(T executor)Unwrap TTL wrapper executor to the original/underneath one.
-
-
-
Method Detail
-
getTtlExecutor
@Nullable public static Executor getTtlExecutor(@Nullable Executor executor)
TransmittableThreadLocalWrapper ofExecutor, transmit theTransmittableThreadLocalfrom the task submit time ofRunnableto the execution time ofRunnable.NOTE: sine v2.12.0 the idempotency of return wrapper Executor is changed to true, so the wrapper Executor can be cooperation the usage of "Decorate Runnable and Callable".
about idempotency: if is idempotent, allowed submit the
TtlRunnable/TtlCallableto the wrapper Executor; otherwise throwIllegalStateException.- Parameters:
executor- input Executor- Returns:
- wrapped Executor
- See Also:
TtlRunnable.get(Runnable, boolean, boolean),TtlCallable.get(Callable, boolean, boolean)
-
getTtlExecutorService
@Nullable public static ExecutorService getTtlExecutorService(@Nullable ExecutorService executorService)
TransmittableThreadLocalWrapper ofExecutorService, transmit theTransmittableThreadLocalfrom the task submit time ofRunnableorCallableto the execution time ofRunnableorCallable.NOTE: sine v2.12.0 the idempotency of return wrapper ExecutorService is changed to true, so the wrapper ExecutorService can be cooperation the usage of "Decorate Runnable and Callable".
about idempotency: if is idempotent, allowed submit the
TtlRunnable/TtlCallableto the wrapper ExecutorService; otherwise throwIllegalStateException.- Parameters:
executorService- input ExecutorService- Returns:
- wrapped ExecutorService
- See Also:
TtlRunnable.get(Runnable, boolean, boolean),TtlCallable.get(Callable, boolean, boolean)
-
getTtlScheduledExecutorService
@Nullable public static ScheduledExecutorService getTtlScheduledExecutorService(@Nullable ScheduledExecutorService scheduledExecutorService)
TransmittableThreadLocalWrapper ofScheduledExecutorService, transmit theTransmittableThreadLocalfrom the task submit time ofRunnableorCallableto the execution time ofRunnableorCallable.NOTE: sine v2.12.0 the idempotency of return wrapper ScheduledExecutorService is changed to true, so the wrapper ScheduledExecutorService can be cooperation the usage of "Decorate Runnable and Callable".
about idempotency:if is idempotent, allowed submit the
TtlRunnable/TtlCallableto the wrapper scheduledExecutorService; otherwise throwIllegalStateException.- Parameters:
scheduledExecutorService- input scheduledExecutorService- Returns:
- wrapped scheduledExecutorService
- See Also:
TtlRunnable.get(Runnable, boolean, boolean),TtlCallable.get(Callable, boolean, boolean)
-
isTtlWrapper
public static <T extends Executor> boolean isTtlWrapper(@Nullable T executor)
check the executor is TTL wrapper executor 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:
getTtlExecutor(Executor),getTtlExecutorService(ExecutorService),getTtlScheduledExecutorService(ScheduledExecutorService),unwrap(Executor)
-
unwrap
@Nullable public static <T extends Executor> T unwrap(@Nullable T executor)
Unwrap TTL wrapper executor 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:
getTtlExecutor(Executor),getTtlExecutorService(ExecutorService),getTtlScheduledExecutorService(ScheduledExecutorService),isTtlWrapper(Executor),TtlUnwrap.unwrap(Object)
-
getDisableInheritableThreadFactory
@Nullable public static ThreadFactory getDisableInheritableThreadFactory(@Nullable ThreadFactory threadFactory)
Wrapper ofThreadFactory, disable inheritable.- Parameters:
threadFactory- input thread factory- Since:
- 2.10.0
- See Also:
DisableInheritableThreadFactory
-
getDefaultDisableInheritableThreadFactory
@Nullable public static ThreadFactory getDefaultDisableInheritableThreadFactory()
Wrapper ofExecutors.defaultThreadFactory(), disable inheritable.- Since:
- 2.10.0
- See Also:
getDisableInheritableThreadFactory(ThreadFactory)
-
isDisableInheritableThreadFactory
public static boolean isDisableInheritableThreadFactory(@Nullable ThreadFactory threadFactory)
check theThreadFactoryisDisableInheritableThreadFactoryor not.- Since:
- 2.10.0
- See Also:
DisableInheritableThreadFactory
-
unwrap
@Nullable public static ThreadFactory unwrap(@Nullable ThreadFactory threadFactory)
UnwrapDisableInheritableThreadFactoryto the original/underneath one.- Since:
- 2.10.0
- See Also:
TtlUnwrap.unwrap(Object),DisableInheritableThreadFactory
-
-