J.14 Creating and Executing Threads with the Executor
Framework
This section demonstrates how to perform concurrent tasks in an application by using Executors
and Runnable
objects.
Creating Concurrent Tasks with the Runnable
Interface
You implement the Runnable
interface (of package java.lang
) to specify a task that can execute concurrently with other tasks. The Runnable
interface declares the single method run
, which contains the code that defines the task that a Runnable
object should perform.
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 ...
Get Android How to Program, 3/e 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.