Class BoxExecutor

java.lang.Object
ortus.boxlang.runtime.async.executors.BoxExecutor
Direct Known Subclasses:
ExecutorRecord

public class BoxExecutor extends Object
BoxLang Executor class that wraps ExecutorService instances with enhanced health monitoring, detailed statistics, and activity tracking functionality.
  • Constructor Details

    • BoxExecutor

      public BoxExecutor(ExecutorService executor, String name, AsyncService.ExecutorType type, Integer maxThreads)
      Constructor
      Parameters:
      executor - The executor service
      name - The name of the executor
      type - The executor type
      maxThreads - The max threads, if applicable
  • Method Details

    • executor

      public ExecutorService executor()
    • name

      public String name()
    • type

    • maxThreads

      public Integer maxThreads()
    • scheduledExecutor

      public BoxScheduledExecutor scheduledExecutor()
      Get the executor service casted as a BoxScheduledExecutor
      Returns:
      The executor service
    • getLogger

      public BoxLangLogger getLogger()
      Get the executor logger
    • isHealthy

      public boolean isHealthy()
      Check if executor is healthy (simple boolean check) Uses current stats to determine health
      Returns:
      boolean True if status is "healthy" or "idle"
    • isTerminated

      public boolean isTerminated()
      Returns true if all tasks have completed following shut down.
    • isTerminating

      public boolean isTerminating()
      Returns true if this executor is in the process of terminating after shutdown() or shutdownNow() but has not completely terminated.
    • isShutdown

      public boolean isShutdown()
      Returns true if this executor has been shut down.
    • awaitTermination

      public boolean awaitTermination(Long timeout, TimeUnit unit)
      Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
      Parameters:
      timeout - The maximum time to wait
      unit - The time unit to use
      Returns:
      true if all tasks have completed following shut down
    • shutdown

      public BoxExecutor shutdown()
      Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.
      Returns:
      This executor for chaining
    • shutdownNow

      public List<Runnable> shutdownNow()
      Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.
      Returns:
      list of tasks that never commenced execution
    • getQueue

      public BlockingQueue<Runnable> getQueue()
      Returns the task queue used by this executor. If the executor has no queue, an empty queue is returned for compatibility.
      Returns:
      A queue that holds the tasks submitted to this executor.
    • getActiveCount

      public int getActiveCount()
      Returns the approximate number of threads that are actively executing tasks.
    • getTaskCount

      public long getTaskCount()
      Returns the approximate total number of tasks that have ever been scheduled for execution.
    • getCompletedTaskCount

      public long getCompletedTaskCount()
      Returns the approximate total number of tasks that have completed execution.
    • getCorePoolSize

      public int getCorePoolSize()
      Returns the core number of threads.
    • getLargestPoolSize

      public int getLargestPoolSize()
      Returns the largest number of threads that have ever simultaneously been in the pool.
    • getMaximumPoolSize

      public int getMaximumPoolSize()
      Returns the maximum allowed number of threads.
    • getPoolSize

      public int getPoolSize()
      Returns the current number of threads in the pool.
    • shutdownQuiet

      public void shutdownQuiet()
      Calls the `shutdown` of the executor - which is non blocking
    • shutdownAndAwaitTermination

      public void shutdownAndAwaitTermination(Long timeout, TimeUnit unit)
      Blocks until all tasks have completed execution after a shutdown request, or the timeout occurs, or the current thread is interrupted, whichever happens first.
      Parameters:
      timeout - The maximum time to wait
      unit - The time unit to use, available units are: days, hours, microseconds, milliseconds, minutes, nanoseconds, and seconds. The default
    • newTask

      public ScheduledTask newTask(String name)
      Build out a new scheduled task bound to this executor Calling this method is not the mean that the task will be executed. It just builds out a record for the task. It will be your job to call the start() method on it to start the task. This can be used to create a task and then schedule it to run at a later time and not bound to a Scheduler.
      Parameters:
      name - The name of the task
      Returns:
      The new task bound to this executor
    • newTask

      public ScheduledTask newTask()
      Build out a new scheduled task bound to this executor Calling this method is not the mean that the task will be executed. It just builds out a record for the task. It will be your job to call the start() method on it to start the task. This can be used to create a task and then schedule it to run at a later time and not bound to a Scheduler. The name will be auto-generated
      Returns:
      The new task bound to this executor
    • getStats

      public IStruct getStats()
      Our very own stats struct map to give you a holistic view of the executor with enhanced health monitoring and detailed metrics
      Returns:
      The stats struct with comprehensive information
    • submit

      public Future<?> submit(Runnable runnable)
      Submit proxy to the executor with activity tracking
      Parameters:
      runnable - The runnable to submit
      Returns:
      The future
    • submit

      public Future<?> submit(Callable<?> callable)
      Submit proxy to the executor with activity tracking
      Parameters:
      callable - The callable to submit
      Returns:
      The future
    • submitAndGet

      public Object submitAndGet(Callable<? extends Object> fn)
      Method to submit a Callable to the executor and return the result
      Parameters:
      fn - The Runnable lambda to submit
      Returns:
      The result of the submission and retrieval
    • submitAndGet

      public Object submitAndGet(ForkJoinTask<? extends Object> fn)
      Method to submit a Callable to the executor and return the result
      Parameters:
      fn - The Runnable lambda to submit
      Returns:
      The result of the submission and retrieval
    • submitAndGet

      public Object submitAndGet(Runnable fn)
      Method to submit a runnable to the executor and return the result
      Parameters:
      fn - The Runnable lambda to submit
      Returns:
      The result of the submission and retrieval