Skip to Content
Native Mobile Development
book

Native Mobile Development

by Shaun Lewis, Mike Dunn
November 2019
Intermediate to advanced
394 pages
9h 44m
English
O'Reilly Media, Inc.
Content preview from Native Mobile Development

Chapter 8. Concurrency (Multi-Threading)

Concurrency, also sometimes known as parallelism or multi-threading, is the concept of performing multiple tasks at the same time, dividing the computer’s resources into distinct entities that very quickly alternate between each other until any entity has its entire workload completed, at which time it’s removed from this procedure. The act of computation jumping between different processes (small-p) is known as “context switching,” which has a more common, and very different, definition in computer science (switching your brain’s resources from one domain to another).

Tasks

In this chapter, you’ll learn to:

  1. Perform a task in a background thread.

  2. Act on the results of work performed in the background thread on the main thread.

Android

In Java, a processing context is known as a Thread. A Thread is an object instance and is created exactly as you’d expect:

A Thread is passed in a Runnable instance. Once a thread is started (by calling the start method), the thread invokes the run method of that Runnable. As soon as that method is complete (by returning or throwing), the thread terminates.

In Android, there is a single Thread instance that all work is performed on by default, including and especially UI work. That is important—in fact, the concept is sometimes called the “UI thread,” but is more commonly known as the “main” thread. Since the first release of ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Pro iPhone Development with SwiftUI: Design and Manage Top Quality Apps

Pro iPhone Development with SwiftUI: Design and Manage Top Quality Apps

Wallace Wang
Ionic in Action

Ionic in Action

Jeremy Wilken
What Employees Want Most in Uncertain Times

What Employees Want Most in Uncertain Times

Kristine W. Powers, Jessica B.B. Diaz

Publisher Resources

ISBN: 9781492052869Errata PageSupplemental Content