Executors
Here you can configure the global thread executors in BoxLang.
BoxLang allows you to register named executors globally. The JSON object key is the name of the executor and the value is another object with the type
and a threads
property, which is optional. By default, BoxLang pre-configures two executors for you:
If you omit the threads
on the executors, we will use the default of 20 threads.
Available Executor Types
The available types of executors you can register in BoxLang are:
cached
Creates a thread pool that creates new threads as needed but will reuse previously constructed threads when available.
Use Case: Best for applications that execute many short-lived asynchronous tasks.
fixed
Creates a thread pool with a fixed number of threads. If all threads are busy, new tasks will wait in a queue until a thread is available.
Use Case: Ideal for situations where you need a consistent number of threads to handle tasks, ensuring that the resource usage remains predictable.
fork_join
Designed for tasks that can be broken down into smaller tasks and executed in parallel. It uses a work-stealing algorithm to optimize throughput.
Use Case: Suitable for recursive algorithms, parallel processing, and tasks that can be divided into subtasks.
scheduled
Allows tasks to be scheduled to run after a given delay or to execute periodically with a fixed number of threads.
Use Case: Perfect for tasks that need to run at regular intervals or after a specific delay, such as periodic maintenance or monitoring tasks.
single
Creates a single-threaded executor that executes tasks sequentially.
Use Case: Useful for scenarios where tasks must be executed in order, ensuring that no two tasks run simultaneously.
virtual
It uses virtual threads, also known as fibers, which are lightweight and managed by the JVM, providing high scalability with low overhead.
Use Case: Best for high-concurrency applications where many lightweight tasks need to be managed efficiently.
work_stealing
Creates a pool of threads that attempts to keep all threads busy by stealing tasks from other threads when they have completed their work.
Use Case: Excellent for irregular workloads where tasks may vary significantly in complexity and duration, optimizing resource usage and improving performance.
As long as they implement the executor services interfaces, you can use them in BoxLang.
Last updated
Was this helpful?