public class JdkExecutorService extends AbstractDependentService implements ExecutorService
This service is thread-safe.
com.google.common.util.concurrent.Service.Listener, com.google.common.util.concurrent.Service.State
Constructor and Description |
---|
JdkExecutorService()
Construct.
|
Modifier and Type | Method and Description |
---|---|
protected <T> Callable<T> |
createTask(callable : Callable<T>)
Create a task with the given callable.
|
protected Runnable |
createTask(runnable : Runnable)
Create a task with the given runnable.
|
protected void |
doStart() |
protected void |
doStop() |
void |
execute(task : Runnable)
Submit a task to the executor service.
|
int |
executeMultipleTimesInParallelAndWaitForTermination(task : Runnable,
nbExecutions : int,
runGroupSize : int)
Submit a single task multiple times to the executor service.
|
ExecutorService |
getExecutorService()
Replies the JVM executor service used by service.
|
Class<? extends com.google.common.util.concurrent.Service> |
getServiceType()
Replies the service interface implemented by this service.
|
void |
purge()
Remove any canceled/terminated tasks from the lists of tasks.
|
<T> ScheduledFuture<T> |
schedule(command : Callable<T>,
delay : long,
unit : TimeUnit)
Schedule the given task.
|
ScheduledFuture<?> |
schedule(command : Runnable,
delay : long,
unit : TimeUnit)
Schedule the given task.
|
ScheduledFuture<?> |
scheduleAtFixedRate(command : Runnable,
initialDelay : long,
period : long,
unit : TimeUnit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the
given period; that is executions will commence after initialDelay then initialDelay+period, then initialDelay + 2 * period,
and so on.
|
ScheduledFuture<?> |
scheduleWithFixedDelay(command : Runnable,
initialDelay : long,
delay : long,
unit : TimeUnit)
Creates and executes a periodic action that becomes enabled first after the given initial delay, and subsequently with the
given delay between the termination of one execution and the commencement of the next.
|
<T> Future<T> |
submit(task : Callable<T>)
Submit a task to the executor service.
|
Future<?> |
submit(task : Runnable)
Submit a task to the executor service.
|
<T> Future<T> |
submit(task : Runnable,
result : T)
Submit a task to the executor service.
|
getServiceDependencies, getServiceWeakDependencies
addListener, awaitRunning, awaitRunning, awaitTerminated, awaitTerminated, failureCause, isRunning, notifyFailed, notifyStarted, notifyStopped, startAsync, state, stopAsync, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
neverReturn
getServiceDependencies, getServiceWeakDependencies
public final def
getServiceType() : Class<? extends com.google.common.util.concurrent.Service>
DependentService
getServiceType
in interface DependentService
protected def
doStart() : void
doStart
in class com.google.common.util.concurrent.AbstractService
protected def
doStop() : void
doStop
in class com.google.common.util.concurrent.AbstractService
protected def
createTask(runnable : Runnable) : Runnable
JdkExecutorService
runnable
- the runnable.protecteddef
createTask(callable : Callable<T>) : Callable<T>with
<T>
JdkExecutorService
T
- the type of the returned value.callable
- the callable.public def
execute(task : Runnable) : void
ExecutorService
execute
in interface ExecutorService
task
- the task to submit.if you want a future.
public def
executeMultipleTimesInParallelAndWaitForTermination(task : Runnable,
nbExecutions : int,
runGroupSize : int) : int
throws InterruptedException
ExecutorService
The same task instance will be submit to the executor service.
runGroupSize
indicates how many number of times the task will be run on
a single thread.
This function is equivalent to:
for(i in [ 1 .. (nbExecutions/runGroupSize) ])
do
execute({
for(j in [1..runGroupSize]) {
task.run
}
})
done
Caution: if a task
is failing, the exception will be output as an uncaught exception.
executeMultipleTimesInParallelAndWaitForTermination
in interface ExecutorService
task
- the task to submit.nbExecutions
- the number of times the task must be run, usually greater than 1.runGroupSize
- the number of tasks to be run by a single thread.InterruptedException
- when the function cannot wait for task termination.public def
submit(task : Runnable) : Future<?>
ExecutorService
submit
in interface ExecutorService
task
- the task to submit.if you don't want a future.
publicdef
submit(task : Runnable, result : T) : Future<T>with
<T>
ExecutorService
submit
in interface ExecutorService
T
- - the type of the value replied by the task.task
- the task to submit.result
- result to return after the execution.publicdef
submit(task : Callable<T>) : Future<T>with
<T>
ExecutorService
submit
in interface ExecutorService
T
- - the type of the value replied by the task.task
- the task to submit.public def
schedule(command : Runnable,
delay : long,
unit : TimeUnit) : ScheduledFuture<?>
ExecutorService
schedule
in interface ExecutorService
command
- task to rundelay
- delay for waiting before launching the commandunit
- time unit of the delaypublicdef
schedule(command : Callable<T>, delay : long, unit : TimeUnit) : ScheduledFuture<T>with
<T>
ExecutorService
schedule
in interface ExecutorService
T
- - the type of the value replied by the task.command
- task to rundelay
- delay for waiting before launching the commandunit
- time unit of the delaypublic def
scheduleAtFixedRate(command : Runnable,
initialDelay : long,
period : long,
unit : TimeUnit) : ScheduledFuture<?>
ExecutorService
scheduleAtFixedRate
in interface ExecutorService
command
- task to runinitialDelay
- the time to delay first executionperiod
- the period between successive executionsunit
- รจ the time unit of the initialDelay and period parameterspublic def
scheduleWithFixedDelay(command : Runnable,
initialDelay : long,
delay : long,
unit : TimeUnit) : ScheduledFuture<?>
ExecutorService
scheduleWithFixedDelay
in interface ExecutorService
command
- the task to executeinitialDelay
- the time to delay first executiondelay
- the delay between the termination of one execution and the start of the nextunit
- the time unit of the initialDelay and delay parameterspublic def
getExecutorService() : ExecutorService
ExecutorService
getExecutorService
in interface ExecutorService
public def
purge() : void
ExecutorService
purge
in interface ExecutorService
Copyright © 2018 the original authors or authors.