Class CommonTaskExecutor
- java.lang.Object
-
- java.util.concurrent.AbstractExecutorService
-
- io.opentelemetry.javaagent.tooling.CommonTaskExecutor
-
- All Implemented Interfaces:
Executor,ExecutorService
public final class CommonTaskExecutor extends AbstractExecutorService
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCommonTaskExecutor.Task<T>
-
Field Summary
Fields Modifier and Type Field Description static CommonTaskExecutorINSTANCE
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanawaitTermination(long timeout, TimeUnit unit)voidexecute(Runnable command)booleanisShutdown()booleanisTerminated()<T> ScheduledFuture<?>scheduleAtFixedRate(CommonTaskExecutor.Task<T> task, T target, long initialDelay, long period, TimeUnit unit, String name)Runtaskperiodically providing it withtargetvoidshutdown()List<Runnable>shutdownNow()
-
-
-
Field Detail
-
INSTANCE
public static final CommonTaskExecutor INSTANCE
-
-
Method Detail
-
scheduleAtFixedRate
public <T> ScheduledFuture<?> scheduleAtFixedRate(CommonTaskExecutor.Task<T> task, T target, long initialDelay, long period, TimeUnit unit, String name)
Runtaskperiodically providing it withtargetImportant implementation detail here is that internally we do not hold any strong references to
targetwhich means it can be GCed even while periodic task is still scheduled.If
targetis GCed periodic task is canceled.This method should be able to schedule task in majority of cases. The only reasonable case when this would fail is when task is being scheduled during JVM shutdown. In this case this method will return 'fake' future that can still be canceled to avoid confusing callers.
- Parameters:
task- task to run. Important: must not hold any strong references to target (or anything else non static)target- target object to pass to taskinitialDelay- initialDelay, seeScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)period- period, seeScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)unit- unit, seeScheduledExecutorService.scheduleAtFixedRate(Runnable, long, long, TimeUnit)name- name to use in logs when task cannot be scheduled- Returns:
- future that can be canceled
-
shutdown
public void shutdown()
-
isShutdown
public boolean isShutdown()
-
isTerminated
public boolean isTerminated()
-
awaitTermination
public boolean awaitTermination(long timeout, TimeUnit unit) throws InterruptedException- Throws:
InterruptedException
-
execute
public void execute(Runnable command)
-
-