Class BambooVirtualExecutors

java.lang.Object
com.atlassian.bamboo.concurrent.BambooVirtualExecutors

public class BambooVirtualExecutors extends Object
Since:
12.0
  • Constructor Details

    • BambooVirtualExecutors

      public BambooVirtualExecutors()
  • Method Details

    • executeInBatches

      public static <T> void executeInBatches(Iterable<? extends T> items, Consumer<? super T> action, int batchSize)
      Executes a given action on a list of items in batches using a virtual ExecutorService.

      This method divides the provided list of items into smaller batches and processes each batch concurrently using the Executors.newVirtualThreadPerTaskExecutor(). The action to be performed on each item is specified as a Consumer. The method ensures that all items are processed, and it handles exceptions gracefully to avoid interrupting the execution of other tasks.

      Behavior:

      • The method splits the input list into batches of a predefined size (e.g., 100 items per batch).
      • Each batch is submitted to the ExecutorService for concurrent execution.
      • Each task is executed on a separate virtual lightweight thread, ensuring efficient resource utilization.
      • If an exception occurs while processing an item, it is caught, allowing other items to continue processing.
      • If the input list is empty, the method returns immediately without submitting any tasks.
      • The method blocks until all batches are processed.
      Parameters:
      items - The list of items to process.
      action - The action to perform on each item.
      batchSize - Number of items to proceed at once.
      Throws:
      RuntimeException - if an error occurs during task execution.
    • executeInBatchesWithSystemAuthority

      public static <T> void executeInBatchesWithSystemAuthority(Iterable<? extends T> items, Consumer<? super T> action, int batchSize)
      Executes a collection of tasks in batches using virtual threads, ensuring that each task is executed with system authority. This method leverages virtual threads for lightweight concurrency and applies a security context to each task. Additionally, the current thread is escalated to system authority before executing the tasks.
      Parameters:
      items - The list of items to process.
      action - The action to perform on each item.
      batchSize - Number of items to proceed at once.
      Throws:
      RuntimeException - if an error occurs during task execution.