coldbox.system.async.executors

Class ScheduledExecutor

lucee.Component
    extended by coldbox.system.async.executors.Executor
      extended by coldbox.system.async.executors.ScheduledExecutor

This is a specialized executor that deals with scheduled tasks using the Java ScheduledExecutorService. With it, you will be able to create different types of tasks: - `submit()` : Submit tasks just like a normal executors (can return results) - `schedule()` : Schedule one-time executing tasks with or without delays (can return results) - `scheduleAtFixedRate()` : Schedule tasks that will execute on a specific frequency (do not return results) - `scheduleWithFixedDelay()` : Schedule tasks that will execute on a specific delayed schedule after each of them completes (do not return results) All of the scheduling methods will return a ScheduledFuture object that you can use to monitor and get results from the tasks at hand, if any.

Class Attributes:
  • singleton
  •  
  • synchronized : false
  •  
  • accessors : true
  •  
  • persistent : false
  •  
    Method Summary
    any buildJavaRunnable(any task, any method)
         Build out a Java Runnable from the incoming cfc/closure/lambda/udf that will be sent to the schedulers.
    coldbox.system.async.executors.ScheduledTask newSchedule(any task, [any method='run'])
         Build out a new scheduled task.
    coldbox.system.async.executors.ScheduledTask newTask([any name='[runtime expression]'], [any task], [any method='run'])
         Build out a new scheduled task representation.
    coldbox.system.async.executors.ScheduledFuture schedule(any task, [numeric delay='0'], [any timeUnit='milliseconds'], [any method='run'])
         This method is used to register a runnable CFC, closure or lambda so it can.
    coldbox.system.async.executors.ScheduledFuture scheduleAtFixedRate(any task, numeric every, [numeric delay='0'], [any timeUnit='milliseconds'], [any method='run'])
         Creates and executes a periodic action that becomes enabled first after.
    coldbox.system.async.executors.ScheduledFuture scheduleWithFixedDelay(any task, numeric spacedDelay, [numeric delay='0'], [any timeUnit='milliseconds'], [any method='run'])
         Creates and executes a periodic action that becomes enabled first after the given.
     
    Methods inherited from class coldbox.system.async.executors.Executor
    awaitTermination, getActiveCount, getCompletedTaskCount, getCorePoolSize, getLargestPoolSize, getMaximumPoolSize, getName, getNative, getPoolSize, getQueue, getStats, getTaskCount, init, isShutdown, isTerminated, isTerminating, setName, setNative, shutdown, shutdownNow, submit
     
    Methods inherited from class lucee.Component
    None

    Method Detail

    buildJavaRunnable

    public any buildJavaRunnable(any task, any method)

    Build out a Java Runnable from the incoming cfc/closure/lambda/udf that will be sent to the schedulers.

    Parameters:
    task - The runnable task closure/lambda/cfc
    method - The default method to execute if the runnable is a CFC, defaults to `run()`
    Returns:
    A java.lang.Runnable

    newSchedule Deprecated

    public coldbox.system.async.executors.ScheduledTask newSchedule(any task, [any method='run'])

    Build out a new scheduled task

    Deprecated:
    DO NOT USE, use newTask() instead
    Parameters:
    task - The closure or cfc that represents the task
    method - The method on the cfc to call, defaults to "run" (optional)

    newTask

    public coldbox.system.async.executors.ScheduledTask newTask([any name='[runtime expression]'], [any task], [any method='run'])

    Build out a new scheduled task representation. Calling this method does not mean that the task is executed.

    Parameters:
    name - The name of the task
    task - The closure or cfc that represents the task (optional)
    method - The method on the cfc to call, defaults to "run" (optional)

    schedule

    public coldbox.system.async.executors.ScheduledFuture schedule(any task, [numeric delay='0'], [any timeUnit='milliseconds'], [any method='run'])

    This method is used to register a runnable CFC, closure or lambda so it can execute as a scheduled task according to the delay and period you have set in the Schedule. The method will register the runnable and send it for execution, the result is a ScheduledFuture. Periodic tasks do NOT return a result, while normal delayed tasks can.

    Parameters:
    task - The runnable task closure/lambda/cfc
    delay - The time to delay the first execution
    timeUnit - The time unit to use, available units are: days, hours, microseconds, milliseconds, minutes, nanoseconds, and seconds. The default is milliseconds
    method - The default method to execute if the runnable is a CFC, defaults to `run()`
    Returns:
    ScheduledFuture representing pending completion of the task and whose get() method will return null upon completion
    Throws:
    RejectedExecutionException - if the task cannot be scheduled for execution

    scheduleAtFixedRate

    public coldbox.system.async.executors.ScheduledFuture scheduleAtFixedRate(any task, numeric every, [numeric delay='0'], [any timeUnit='milliseconds'], [any method='run'])

    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 delay then delay+every, then delay + 2 * every, and so on. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor. If any execution of this task takes longer than its period, then subsequent executions may start late, but will not concurrently execute.

    Parameters:
    task - The runnable task closure/lambda/cfc
    every - The period between successive executions
    delay - The time to delay the first execution
    timeUnit - The time unit to use, available units are: days, hours, microseconds, milliseconds, minutes, nanoseconds, and seconds. The default is milliseconds
    method - The default method to execute if the runnable is a CFC, defaults to `run()`
    Returns:
    a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
    Throws:
    IllegalArgumentException - if period less than or equal to zero

    scheduleWithFixedDelay

    public coldbox.system.async.executors.ScheduledFuture scheduleWithFixedDelay(any task, numeric spacedDelay, [numeric delay='0'], [any timeUnit='milliseconds'], [any method='run'])

    Creates and executes a periodic action that becomes enabled first after the given delay, and subsequently with the given spacedDelay between the termination of one execution and the commencement of the next. If any execution of the task encounters an exception, subsequent executions are suppressed. Otherwise, the task will only terminate via cancellation or termination of the executor.

    Parameters:
    task - The runnable task closure/lambda/cfc
    spacedDelay - The delay between the termination of one execution and the commencement of the next
    delay - The time to delay the first execution
    timeUnit - The time unit to use, available units are: days, hours, microseconds, milliseconds, minutes, nanoseconds, and seconds. The default is milliseconds
    method - The default method to execute if the runnable is a CFC, defaults to `run()`
    Returns:
    a ScheduledFuture representing pending completion of the task, and whose get() method will throw an exception upon cancellation
    Throws:
    IllegalArgumentException - if spacedDelay less than or equal to zero