Class JdbcThreadUtils


  • public class JdbcThreadUtils
    extends Object
    Utility class for executing tasks in parallel with proper context handling.
    • Constructor Detail

      • JdbcThreadUtils

        public JdbcThreadUtils()
    • Method Detail

      • parallelMap

        public static <T,​R> List<R> parallelMap​(Collection<T> items,
                                                      IDatabricksConnectionContext connectionContext,
                                                      int maxThreads,
                                                      int timeoutSeconds,
                                                      Function<T,​R> task,
                                                      ExecutorService executor)
                                               throws SQLException
        Executes tasks concurrently with appropriate context management, utilizing a provided executor service (which can be null, in which case a new one will be created).
        Type Parameters:
        T - Type of input items
        R - Type of result
        Parameters:
        items - The items to process
        connectionContext - The connection context to propagate to worker threads
        maxThreads - Maximum number of threads to use (when creating internal executor)
        timeoutSeconds - Timeout in seconds
        task - The task to execute for each item
        executor - Optional executor service to use; if null, an internal one will be created
        Returns:
        List of results from all tasks
        Throws:
        SQLException - If an error occurs during execution
      • parallelFlatMap

        public static <T,​R> List<R> parallelFlatMap​(Collection<T> items,
                                                          IDatabricksConnectionContext connectionContext,
                                                          int maxThreads,
                                                          int timeoutSeconds,
                                                          Function<T,​Collection<R>> task,
                                                          ExecutorService executor)
                                                   throws SQLException
        Executes tasks in parallel, collecting and flattening all results, utilizing a provided executor service (which can be null, in which case a new one will be created).
        Type Parameters:
        T - Type of input items
        R - Type of result
        Parameters:
        items - The items to process
        connectionContext - The connection context to propagate to worker threads
        maxThreads - Maximum number of threads to use
        timeoutSeconds - Timeout in seconds
        task - The task to execute for each item, producing a collection of results
        executor - Optional executor service to use; if null, an internal one will be created
        Returns:
        Flattened list of all results
        Throws:
        SQLException - If an error occurs during execution