# IdlingThreadPoolExecutor

Artifact: [androidx.test.espresso.idling:idling-concurrent](https://developer.android.com/jetpack/androidx/releases/test-espresso-idling) [View Source](https://cs.android.com/search?q=file:androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor.java+class:androidx.test.espresso.idling.concurrent.IdlingThreadPoolExecutor)

*** ** * ** ***

<br />

```
class IdlingThreadPoolExecutor : ThreadPoolExecutor, IdlingResource
```

<br />

|---|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) ||||
| ↳ | [java.util.concurrent.AbstractExecutorService](https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService.html) |||
|   | ↳ | [java.util.concurrent.ThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html) ||
|   |   | ↳ | [androidx.test.espresso.idling.concurrent.IdlingThreadPoolExecutor](https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor) |

*** ** * ** ***

A `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html` that can be registered as an `https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource` with Espresso.

Overrides parent methods to monitor threads starting, and finishing execution. Uses `https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/CountingIdlingResource` to track number of active tasks.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor#IdlingThreadPoolExecutor(java.lang.String,int,int,long,java.util.concurrent.TimeUnit,java.util.concurrent.BlockingQueue<java.lang.Runnable>,java.util.concurrent.ThreadFactory)( resourceName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, corePoolSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, maximumPoolSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, keepAliveTime: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, unit: https://developer.android.com/reference/java/util/concurrent/TimeUnit.html!, workQueue: https://developer.android.com/reference/java/util/concurrent/BlockingQueue.html<https://developer.android.com/reference/java/lang/Runnable.html!>!, threadFactory: https://developer.android.com/reference/java/util/concurrent/ThreadFactory.html! )` Creates a new `IdlingThreadPoolExecutor` with the given initial parameters and default rejected execution handler. |

| ### Public functions |
|---|---|
| `synchronized https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor#execute(java.lang.Runnable)(command: https://developer.android.com/reference/java/lang/Runnable.html!)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor#getName()()` Returns the name of the resources (used for logging and idempotency of registration). |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor#isIdleNow()()` Returns `true` if resource is currently idle. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor#registerIdleTransitionCallback(androidx.test.espresso.IdlingResource.ResourceCallback)( callback: https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.ResourceCallback! )` Registers the given `https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.ResourceCallback` with the resource. |

| ### Protected functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor#afterExecute(java.lang.Runnable,java.lang.Throwable)(r: https://developer.android.com/reference/java/lang/Runnable.html!, t: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-throwable/index.html!)` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/test/espresso/idling/concurrent/IdlingThreadPoolExecutor#terminated()()` |

### Inherited functions

From [java.util.concurrent.AbstractExecutorService](https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService.html) `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/java/util/concurrent/Future.html<T!>!>!` `<T> https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService.html#invokeAll(java.util.Collection&lt;? extends java.util.concurrent.Callable&lt;T&gt;&gt;)(tasks: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<https://developer.android.com/reference/java/util/concurrent/Callable.html<T!>!>!)` `T!` `<T> https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService.html#invokeAny(java.util.Collection&lt;? extends java.util.concurrent.Callable&lt;T&gt;&gt;)(tasks: (https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-collection/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-collection/index.html<https://developer.android.com/reference/java/util/concurrent/Callable.html<T!>!>!)` `https://developer.android.com/reference/java/util/concurrent/RunnableFuture.html<T!>!` `<T> https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService.html#newTaskFor(java.lang.Runnable, T)(runnable: https://developer.android.com/reference/java/lang/Runnable.html!, value: T!)` `https://developer.android.com/reference/java/util/concurrent/Future.html<*>!` `https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService.html#submit(java.lang.Runnable)(task: https://developer.android.com/reference/java/lang/Runnable.html!)` `https://developer.android.com/reference/java/util/concurrent/Future.html<T!>!` `<T> https://developer.android.com/reference/java/util/concurrent/AbstractExecutorService.html#submit(java.lang.Runnable, T)(task: https://developer.android.com/reference/java/lang/Runnable.html!, result: T!)` From [java.util.concurrent.ExecutorService](https://developer.android.com/reference/java/util/concurrent/ExecutorService.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ExecutorService.html#close()()` From [java.util.concurrent.ThreadPoolExecutor](https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html) `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#allowCoreThreadTimeOut(boolean)(value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#allowsCoreThreadTimeOut()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#awaitTermination(long, java.util.concurrent.TimeUnit)(timeout: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, unit: https://developer.android.com/reference/java/util/concurrent/TimeUnit.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#beforeExecute(java.lang.Thread, java.lang.Runnable)(t: https://developer.android.com/reference/java/lang/Thread.html!, r: https://developer.android.com/reference/java/lang/Runnable.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#finalize()()`

**This function is deprecated.**
`https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getActiveCount()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getCompletedTaskCount()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getCorePoolSize()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getKeepAliveTime(java.util.concurrent.TimeUnit)(unit: https://developer.android.com/reference/java/util/concurrent/TimeUnit.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getLargestPoolSize()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getMaximumPoolSize()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getPoolSize()()` `https://developer.android.com/reference/java/util/concurrent/BlockingQueue.html<https://developer.android.com/reference/java/lang/Runnable.html!>!` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getQueue()()` `https://developer.android.com/reference/java/util/concurrent/RejectedExecutionHandler.html!` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getRejectedExecutionHandler()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getTaskCount()()` `https://developer.android.com/reference/java/util/concurrent/ThreadFactory.html!` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#getThreadFactory()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#isShutdown()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#isTerminated()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#isTerminating()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#prestartAllCoreThreads()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#prestartCoreThread()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#purge()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#remove(java.lang.Runnable)(task: https://developer.android.com/reference/java/lang/Runnable.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#setCorePoolSize(int)(corePoolSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#setKeepAliveTime(long, java.util.concurrent.TimeUnit)(time: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html, unit: https://developer.android.com/reference/java/util/concurrent/TimeUnit.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#setMaximumPoolSize(int)(maximumPoolSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#setRejectedExecutionHandler(java.util.concurrent.RejectedExecutionHandler)(handler: https://developer.android.com/reference/java/util/concurrent/RejectedExecutionHandler.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#setThreadFactory(java.util.concurrent.ThreadFactory)(threadFactory: https://developer.android.com/reference/java/util/concurrent/ThreadFactory.html!)` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#shutdown()()` `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-mutable-list/index.html)https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<https://developer.android.com/reference/java/lang/Runnable.html!>!` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#shutdownNow()()` `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` `https://developer.android.com/reference/java/util/concurrent/ThreadPoolExecutor.html#toString()()`

## Public constructors

### IdlingThreadPoolExecutor

```
IdlingThreadPoolExecutor(
    resourceName: String!,
    corePoolSize: Int,
    maximumPoolSize: Int,
    keepAliveTime: Long,
    unit: TimeUnit!,
    workQueue: BlockingQueue<Runnable!>!,
    threadFactory: ThreadFactory!
)
```

Creates a new `IdlingThreadPoolExecutor` with the given initial parameters and default rejected execution handler.

| Parameters |
|---|---|
| `resourceName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | the name of the executor (used for logging and idempotency of registration). |
| `corePoolSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the number of threads to keep in the pool, even if they are idle, unless allowCoreThreadTimeOut is set. |
| `maximumPoolSize: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the maximum number of threads to allow in the pool. |
| `keepAliveTime: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | when the number of threads is greater than the core, this is the maximum time that excess idle threads will wait for new tasks before terminating. |
| `unit: https://developer.android.com/reference/java/util/concurrent/TimeUnit.html!` | the time unit for the keepAliveTime argument. |
| `workQueue: https://developer.android.com/reference/java/util/concurrent/BlockingQueue.html<https://developer.android.com/reference/java/lang/Runnable.html!>!` | the queue to use for holding tasks before they are executed. This queue will hold only the Runnable tasks submitted by the execute method. |
| `threadFactory: https://developer.android.com/reference/java/util/concurrent/ThreadFactory.html!` | the factory to use when the executor creates a new thread. |

## Public functions

### execute

```
synchronized fun execute(command: Runnable!): Unit
```

### getName

```
fun getName(): String!
```

Returns the name of the resources (used for logging and idempotency of registration).

### isIdleNow

```
fun isIdleNow(): Boolean
```

Returns `true` if resource is currently idle. Espresso will **always** call this method from the main thread, therefore it should be non-blocking and return immediately.

### registerIdleTransitionCallback

```
fun registerIdleTransitionCallback(
    callback: IdlingResource.ResourceCallback!
): Unit
```

Registers the given `https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.ResourceCallback` with the resource. Espresso will call this method:

- with its implementation of `https://developer.android.com/reference/kotlin/androidx/test/espresso/IdlingResource.ResourceCallback` so it can be notified asynchronously that your resource is idle
- from the main thread, but you are free to execute the callback's onTransitionToIdle from any thread
- once (when it is initially given a reference to your IdlingResource)

You only need to call this upon transition from busy to idle - if the resource is already idle when the method is called invoking the call back is optional and has no significant impact.

## Protected functions

### afterExecute

```
protected fun afterExecute(r: Runnable!, t: Throwable!): Unit
```

### terminated

```
protected fun terminated(): Unit
```