Class ScheduledExecutorServiceHeaplet

  • All Implemented Interfaces:
    Heaplet

    public class ScheduledExecutorServiceHeaplet
    extends GenericHeaplet
    Heaplet for building ScheduledExecutorService instances.

    Creates a thread pool that can schedule commands to run after a given delay, or to execute periodically.

    Reference:

         
         {
             "type": "ScheduledExecutorService",
             "config": {
                 "corePoolSize":  integer > 0 [ OPTIONAL - default to 1 (will grow as needed)]
                 "gracefulStop":  boolean     [ OPTIONAL - default to true (all running jobs will complete)]
                 "gracePeriod" :  duration    [ OPTIONAL - default to '10 second']
             }
         }
         
     
    Usage:
         
         {
             "type": "ScheduledExecutorService",
             "config": {
                 "corePoolSize": 42 // defaults to 1 (will grow as needed), only positive and non-zero
             }
         }
         
     

    This class supports graceful stop. gracefulStop is a setting that allows a thread pool to wind down nicely before killing aggressively running (and submitted) jobs.

         
         {
             "gracefulStop": false // defaults to true
         }
         
     

    gracefulPeriod attribute defines how long the heaplet should wait for jobs to actually terminate properly.

    Note that this setting is only considered when gracefulStop is set to true.

         
         {
             "gracePeriod": "20 seconds" // defaults to 10 seconds
         }
         
     

    When the period is over, if the executor service is not properly terminated, the heaplet prints a message and drains the queued tasks and notify the running tasks for interruption.

    Note that all configuration attributes can be defined using static expressions (they can't be resolved against context or request objects that are not available at init time).

    See Also:
    ExecutorService.shutdown(), ExecutorService.shutdownNow(), ExecutorService.awaitTermination(long, java.util.concurrent.TimeUnit), ExecutorService.isTerminated()
    • Constructor Detail

      • ScheduledExecutorServiceHeaplet

        public ScheduledExecutorServiceHeaplet()
    • Method Detail

      • destroy

        public void destroy()
        Description copied from interface: Heaplet
        Called to indicate that the object created by the heaplet is going to be dereferenced. This gives the heaplet an opportunity to free any resources that are being held prior to its dereference.
        Specified by:
        destroy in interface Heaplet
        Overrides:
        destroy in class GenericHeaplet