Package org.apache.solr.common.util

## Class ExecutorUtil

- java.lang.Object
- - org.apache.solr.common.util.ExecutorUtil

    public class ExecutorUtil
    extends Object

### Nested Class Summary

Nested Classes
`static interface` `ExecutorUtil.InheritableThreadLocalProvider` Any class which wants to carry forward the threadlocal values to the threads run by threadpools must implement this interface and the implementation should be registered here
`static class` `ExecutorUtil.MDCAwareThreadPoolExecutor`

### Constructor Summary

Constructors
`ExecutorUtil()`

### Method Summary

All Methods Static Methods Concrete Methods
`static void` `addThreadLocalProvider​(ExecutorUtil.InheritableThreadLocalProvider provider)`
`static void` `awaitTermination​(ExecutorService pool)`
`static boolean` `isShutdown​(ExecutorService pool)`
`static boolean` `isSolrServerThread()`
`static boolean` `isTerminated​(ExecutorService pool)`
`static ExecutorService` `newMDCAwareCachedThreadPool​(int maxThreads, int queueCapacity, ThreadFactory threadFactory)`
`static ExecutorService` `newMDCAwareCachedThreadPool​(String name)` Create a cached thread pool using a named thread factory
`static ExecutorService` `newMDCAwareCachedThreadPool​(ThreadFactory threadFactory)` See `Executors.newCachedThreadPool(ThreadFactory)`
`static ExecutorService` `newMDCAwareFixedThreadPool​(int nThreads, ThreadFactory threadFactory)` See `Executors.newFixedThreadPool(int, ThreadFactory)`
`static ExecutorService` `newMDCAwareSingleThreadExecutor​(ThreadFactory threadFactory)` See `Executors.newSingleThreadExecutor(ThreadFactory)`
`static void` `resetThreadLocalProviders()` Resets everything added via `addThreadLocalProvider(InheritableThreadLocalProvider)`.
`static void` `setServerThreadFlag​(Boolean flag)`
`static void` `shutdownAndAwaitTermination​(ExecutorService pool)`
`static void` `shutdownNowAndAwaitTermination​(ExecutorService pool)`
`static <T> Collection<T>` `submitAllAndAwaitAggregatingExceptions​(ExecutorService service, List<? extends Callable<T>> tasks)` Takes an executor and a list of Callables and executes them returning the results as a list.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### ExecutorUtil

    public ExecutorUtil()

### Method Detail

#### resetThreadLocalProviders

    public static void resetThreadLocalProviders()

Resets everything added via `addThreadLocalProvider(InheritableThreadLocalProvider)`. Useful to call at the beginning of tests.

#### addThreadLocalProvider

    public static void addThreadLocalProvider​(ExecutorUtil.InheritableThreadLocalProvider provider)

#### isShutdown

    public static boolean isShutdown​(ExecutorService pool)

#### isTerminated

    public static boolean isTerminated​(ExecutorService pool)

#### shutdownAndAwaitTermination

    public static void shutdownAndAwaitTermination​(ExecutorService pool)

#### shutdownNowAndAwaitTermination

    public static void shutdownNowAndAwaitTermination​(ExecutorService pool)

#### awaitTermination

    public static void awaitTermination​(ExecutorService pool)

#### newMDCAwareFixedThreadPool

    public static ExecutorService newMDCAwareFixedThreadPool​(int nThreads,
                                                             ThreadFactory threadFactory)

See `Executors.newFixedThreadPool(int, ThreadFactory)`

#### newMDCAwareSingleThreadExecutor

    public static ExecutorService newMDCAwareSingleThreadExecutor​(ThreadFactory threadFactory)

See `Executors.newSingleThreadExecutor(ThreadFactory)`

#### newMDCAwareCachedThreadPool

    public static ExecutorService newMDCAwareCachedThreadPool​(String name)

Create a cached thread pool using a named thread factory

#### newMDCAwareCachedThreadPool

    public static ExecutorService newMDCAwareCachedThreadPool​(ThreadFactory threadFactory)

See `Executors.newCachedThreadPool(ThreadFactory)`

#### newMDCAwareCachedThreadPool

    public static ExecutorService newMDCAwareCachedThreadPool​(int maxThreads,
                                                              int queueCapacity,
                                                              ThreadFactory threadFactory)

#### isSolrServerThread

    public static boolean isSolrServerThread()

#### setServerThreadFlag

    public static void setServerThreadFlag​(Boolean flag)

#### submitAllAndAwaitAggregatingExceptions

    public static <T> Collection<T> submitAllAndAwaitAggregatingExceptions​(ExecutorService service,
                                                                           List<? extends Callable<T>> tasks)
                                                                    throws IOException

Takes an executor and a list of Callables and executes them returning the results as a list. The method waits for the return of every task even if one of them throws an exception. If any exception happens it will be thrown, wrapped into an IOException, and other following exceptions will be added as `addSuppressed` to the original exception

Type Parameters:
  `T` - the response type
Parameters:
  `service` - executor
  `tasks` - the list of callables to be executed
Returns:
  results list
Throws:
  `IOException` - in case any exceptions happened