# ThreadPoolExecutor.CallerRunsPolicy

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)

# CallerRunsPolicy

```
open class CallerRunsPolicy : RejectedExecutionHandler
```

|---|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [kotlin.Any](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-any/index.html)                                                                                       ||
| ↳ | [java.util.concurrent.ThreadPoolExecutor.CallerRunsPolicy](https://developer.android.com/reference/kotlin/java/util/concurrent/ThreadPoolExecutor.CallerRunsPolicy#) |

A handler for rejected tasks that runs the rejected task directly in the calling thread of the`execute`method, unless the executor has been shut down, in which case the task is discarded.

## Summary

|                                                                                Public constructors                                                                                 ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [CallerRunsPolicy](https://developer.android.com/reference/kotlin/java/util/concurrent/ThreadPoolExecutor.CallerRunsPolicy#CallerRunsPolicy())`()` Creates a`CallerRunsPolicy`. |

|                                                                                                                                                                                                                                                                                                              Public methods                                                                                                                                                                                                                                                                                                               ||
|----------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| open[Unit](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-unit/index.html) | [rejectedExecution](https://developer.android.com/reference/kotlin/java/util/concurrent/ThreadPoolExecutor.CallerRunsPolicy#rejectedExecution(java.lang.Runnable,%20java.util.concurrent.ThreadPoolExecutor))`(`r:` `[Runnable](https://developer.android.com/reference/kotlin/java/lang/Runnable.html#)!`, `e:` `[ThreadPoolExecutor](https://developer.android.com/reference/kotlin/java/util/concurrent/ThreadPoolExecutor)!`)` Executes task r in the caller's thread, unless the executor has been shut down, in which case the task is discarded. |

## Public constructors

### CallerRunsPolicy

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
CallerRunsPolicy()
```

Creates a`CallerRunsPolicy`.

## Public methods

### rejectedExecution

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels)  

```
open fun rejectedExecution(
    r: Runnable!, 
    e: ThreadPoolExecutor!
): Unit
```

Executes task r in the caller's thread, unless the executor has been shut down, in which case the task is discarded.

|                                                                               Parameters                                                                               ||
|------------|------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `r`        | [Runnable](https://developer.android.com/reference/kotlin/java/lang/Runnable.html#)!:the runnable task requested to be executed                            |
| `executor` | the executor attempting to execute this task                                                                                                               |
| `e`        | [ThreadPoolExecutor](https://developer.android.com/reference/kotlin/java/util/concurrent/ThreadPoolExecutor)!:the executor attempting to execute this task |

|                                Exceptions                                ||
|---------------------------------------------------|-----------------------|
| `java.util.concurrent.RejectedExecutionException` | if there is no remedy |