Class JdbcThreadUtils
java.lang.Object
com.databricks.jdbc.common.util.JdbcThreadUtils
Utility class for executing tasks in parallel with proper context handling.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,R> List <R> parallelFlatMap(Collection<T> items, IDatabricksConnectionContext connectionContext, int maxThreads, int timeoutSeconds, Function<T, Collection<R>> task, ExecutorService executor) 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).static <T,R> List <R> parallelMap(Collection<T> items, IDatabricksConnectionContext connectionContext, int maxThreads, int timeoutSeconds, Function<T, R> task, ExecutorService executor) 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).
-
Constructor Details
-
JdbcThreadUtils
public JdbcThreadUtils()
-
-
Method Details
-
parallelMap
public static <T,R> List<R> parallelMap(Collection<T> items, IDatabricksConnectionContext connectionContext, int maxThreads, int timeoutSeconds, Function<T, R> task, ExecutorService executor) throws SQLExceptionExecutes 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 itemsR- Type of result- Parameters:
items- The items to processconnectionContext- The connection context to propagate to worker threadsmaxThreads- Maximum number of threads to use (when creating internal executor)timeoutSeconds- Timeout in secondstask- The task to execute for each itemexecutor- 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 SQLExceptionExecutes 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 itemsR- Type of result- Parameters:
items- The items to processconnectionContext- The connection context to propagate to worker threadsmaxThreads- Maximum number of threads to usetimeoutSeconds- Timeout in secondstask- The task to execute for each item, producing a collection of resultsexecutor- 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
-