Package com.alibaba.ttl
Class TtlRunnable
- java.lang.Object
-
- com.alibaba.ttl.TtlRunnable
-
- All Implemented Interfaces:
TtlEnhanced,Runnable
public final class TtlRunnable extends Object implements Runnable, TtlEnhanced
TtlRunnabledecorateRunnable, so as to getTransmittableThreadLocaland transmit it to the time ofRunnableexecution, needed when useRunnableto thread pool.Use factory methods
get(java.lang.Runnable)/gets(java.util.Collection<? extends java.lang.Runnable>)to create instance.- Since:
- 0.9.0
- Author:
- Jerry Lee (oldratlee at gmail dot com)
- See Also:
TtlExecutors,Executor,ExecutorService,ThreadPoolExecutor,ScheduledThreadPoolExecutor,Executors
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)static TtlRunnableget(Runnable runnable)Factory method, wrap inputRunnabletoTtlRunnable.static TtlRunnableget(Runnable runnable, boolean releaseTtlValueReferenceAfterRun)Factory method, wrap inputRunnabletoTtlRunnable.static TtlRunnableget(Runnable runnable, boolean releaseTtlValueReferenceAfterRun, boolean idempotent)Factory method, wrap inputRunnabletoTtlRunnable.RunnablegetRunnable()return original/unwrappedRunnable.static List<TtlRunnable>gets(Collection<? extends Runnable> tasks)wrap inputRunnableCollection toTtlRunnableCollection.static List<TtlRunnable>gets(Collection<? extends Runnable> tasks, boolean releaseTtlValueReferenceAfterRun)wrap inputRunnableCollection toTtlRunnableCollection.static List<TtlRunnable>gets(Collection<? extends Runnable> tasks, boolean releaseTtlValueReferenceAfterRun, boolean idempotent)wrap inputRunnableCollection toTtlRunnableCollection.inthashCode()voidrun()wrap methodRunnable.run().StringtoString()static Runnableunwrap(Runnable runnable)UnwrapTtlRunnableto the original/underneath one.static List<Runnable>unwraps(Collection<? extends Runnable> tasks)UnwrapTtlRunnableto the original/underneath one for collection.
-
-
-
Method Detail
-
run
public void run()
wrap methodRunnable.run().
-
get
@Nullable public static TtlRunnable get(@Nullable Runnable runnable)
Factory method, wrap inputRunnabletoTtlRunnable.- Parameters:
runnable- inputRunnable. if input isnull, returnnull.- Returns:
- Wrapped
Runnable - Throws:
IllegalStateException- when input isTtlRunnablealready.
-
get
@Nullable public static TtlRunnable get(@Nullable Runnable runnable, boolean releaseTtlValueReferenceAfterRun)
Factory method, wrap inputRunnabletoTtlRunnable.- Parameters:
runnable- inputRunnable. if input isnull, returnnull.releaseTtlValueReferenceAfterRun- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.- Returns:
- Wrapped
Runnable - Throws:
IllegalStateException- when input isTtlRunnablealready.
-
get
@Nullable public static TtlRunnable get(@Nullable Runnable runnable, boolean releaseTtlValueReferenceAfterRun, boolean idempotent)
Factory method, wrap inputRunnabletoTtlRunnable.- Parameters:
runnable- inputRunnable. if input isnull, returnnull.releaseTtlValueReferenceAfterRun- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.idempotent- is idempotent mode or not. iftrue, just return inputRunnablewhen it'sTtlRunnable, otherwise throwIllegalStateException. Caution:truewill cover up bugs! DO NOT set, only when you know why.- Returns:
- Wrapped
Runnable - Throws:
IllegalStateException- when input isTtlRunnablealready and not idempotent.
-
gets
@Nonnull public static List<TtlRunnable> gets(@Nullable Collection<? extends Runnable> tasks)
wrap inputRunnableCollection toTtlRunnableCollection.- Parameters:
tasks- task to be wrapped. if input isnull, returnnull.- Returns:
- wrapped tasks
- Throws:
IllegalStateException- when input isTtlRunnablealready.
-
gets
@Nonnull public static List<TtlRunnable> gets(@Nullable Collection<? extends Runnable> tasks, boolean releaseTtlValueReferenceAfterRun)
wrap inputRunnableCollection toTtlRunnableCollection.- Parameters:
tasks- task to be wrapped. if input isnull, returnnull.releaseTtlValueReferenceAfterRun- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.- Returns:
- wrapped tasks
- Throws:
IllegalStateException- when input isTtlRunnablealready.
-
gets
@Nonnull public static List<TtlRunnable> gets(@Nullable Collection<? extends Runnable> tasks, boolean releaseTtlValueReferenceAfterRun, boolean idempotent)
wrap inputRunnableCollection toTtlRunnableCollection.- Parameters:
tasks- task to be wrapped. if input isnull, returnnull.releaseTtlValueReferenceAfterRun- release TTL value reference after run, avoid memory leak even ifTtlRunnableis referred.idempotent- is idempotent mode or not. iftrue, just return inputRunnablewhen it'sTtlRunnable, otherwise throwIllegalStateException. Caution:truewill cover up bugs! DO NOT set, only when you know why.- Returns:
- wrapped tasks
- Throws:
IllegalStateException- when input isTtlRunnablealready and not idempotent.
-
unwrap
@Nullable public static Runnable unwrap(@Nullable Runnable runnable)
UnwrapTtlRunnableto the original/underneath one.this method is
null-safe, when inputRunnableparameter isnull, returnnull; if inputRunnableparameter is not aTtlRunnablejust return inputRunnable.- Since:
- 2.10.2
-
unwraps
@Nonnull public static List<Runnable> unwraps(@Nullable Collection<? extends Runnable> tasks)
UnwrapTtlRunnableto the original/underneath one for collection.Invoke
unwrap(Runnable)for each element in input collection.This method is
null-safe, when inputRunnableparameter isnull, return a empty list.- Since:
- 2.10.2
- See Also:
unwrap(Runnable)
-
-