Executing Runnable Objects with an Executor
To allow a Runnable
to perform its task, you must execute it. An Executor object executes Runnable
s. An Executor
does this by creating and managing a group of threads called a thread pool. When an Executor
begins executing a Runnable
, the Executor
calls the Runnable
object’s run
method, which executes in the new thread.
The Executor
interface declares a single method named execute which accepts a Runnable
as an argument. The Executor
assigns every Runnable
passed to its execute
method to one of the available threads in the thread pool. If there are no available threads, the Executor
creates a new thread or waits for a thread to become available and assigns that thread the Runnable
that was passed to ...
Get Android™ How to Program, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.