Class BoxExecutor
java.lang.Object
ortus.boxlang.runtime.async.executors.BoxExecutor
- Direct Known Subclasses:
ExecutorRecord
BoxLang Executor class that wraps ExecutorService instances with enhanced health monitoring,
detailed statistics, and activity tracking functionality.
-
Constructor Summary
ConstructorsConstructorDescriptionBoxExecutor(ExecutorService executor, String name, AsyncService.ExecutorType type, Integer maxThreads) Constructor -
Method Summary
Modifier and TypeMethodDescriptionbooleanawaitTermination(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.executor()intReturns the approximate number of threads that are actively executing tasks.longReturns the approximate total number of tasks that have completed execution.intReturns the core number of threads.intReturns the largest number of threads that have ever simultaneously been in the pool.Get the executor loggerintReturns the maximum allowed number of threads.intReturns the current number of threads in the pool.getQueue()Returns the task queue used by this executor.getStats()Our very own stats struct map to give you a holistic view of the executor with enhanced health monitoring and detailed metricslongReturns the approximate total number of tasks that have ever been scheduled for execution.booleanCheck if executor is healthy (simple boolean check) Uses current stats to determine healthbooleanReturns true if this executor has been shut down.booleanReturns true if all tasks have completed following shut down.booleanReturns true if this executor is in the process of terminating after shutdown() or shutdownNow() but has not completely terminated.name()newTask()Build out a new scheduled task bound to this executor Calling this method is not the mean that the task will be executed.Build out a new scheduled task bound to this executor Calling this method is not the mean that the task will be executed.Get the executor service casted as aBoxScheduledExecutorshutdown()Initiates an orderly shutdown in which previously submitted tasks are executed, but no new tasks will be accepted.voidshutdownAndAwaitTermination(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.Attempts to stop all actively executing tasks, halts the processing of waiting tasks, and returns a list of the tasks that were awaiting execution.voidCalls the `shutdown` of the executor - which is non blockingFuture<?> Submit proxy to the executor with activity trackingFuture<?> Submit proxy to the executor with activity trackingsubmitAndGet(Runnable fn) Method to submit a runnable to the executor and return the resultsubmitAndGet(Callable<? extends Object> fn) Method to submit a Callable to the executor and return the resultsubmitAndGet(ForkJoinTask<? extends Object> fn) Method to submit a Callable to the executor and return the resulttype()
-
Constructor Details
-
BoxExecutor
public BoxExecutor(ExecutorService executor, String name, AsyncService.ExecutorType type, Integer maxThreads) Constructor- Parameters:
executor- The executor servicename- The name of the executortype- The executor typemaxThreads- The max threads, if applicable
-
-
Method Details
-
executor
-
name
-
type
-
maxThreads
-
scheduledExecutor
Get the executor service casted as aBoxScheduledExecutor- Returns:
- The executor service
-
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
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 waitunit- The time unit to use- Returns:
- true if all tasks have completed following shut down
-
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
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
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
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 waitunit- The time unit to use, available units are: days, hours, microseconds, milliseconds, minutes, nanoseconds, and seconds. The default
-
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 thestart()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
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 thestart()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
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
Submit proxy to the executor with activity tracking- Parameters:
runnable- The runnable to submit- Returns:
- The future
-
submit
Submit proxy to the executor with activity tracking- Parameters:
callable- The callable to submit- Returns:
- The future
-
submitAndGet
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
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
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
-