Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the...

16
Android Concurrency Frameworks: Introduction Douglas C. Schmidt [email protected] www.dre.vanderbilt.edu/~schmidt Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA

Transcript of Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the...

Page 1: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

Android Concurrency Frameworks:

Introduction

Douglas C. [email protected]

www.dre.vanderbilt.edu/~schmidt

Institute for Software

Integrated Systems

Vanderbilt University

Nashville, Tennessee, USA

Page 2: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

2

Learning Objectives in this Part of the Lesson• Know the motivations for Android

concurrency & concurrency frameworks

• Recognize the two types of Android concurrency frameworks

Lo

op

er Message

Message

Message

Message

Message

Message

Queue

Message

UI Thread(main thread)

Runnable

Message

Background

Thread A

Handler

Handler

Background

Thread B

AsyncTask

Executor

Handler

Fu

ture

Ta

sk

Page 3: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

3

Learning Objectives in this Part of the Lesson• Know the motivations for Android

concurrency & concurrency frameworks

• Recognize the two types of Android concurrency frameworks, e.g.

• Handler, Messages, & Runnables(HaMeR) framework

See code.tutsplus.com/tutorials/concurrency-on-android-using-hamer-framework--cms-27129

Lo

op

er Message

Message

Message

Message

Message

Message

Queue

Message

UI Thread(main thread)

Runnable

Message

Background

Thread A

Handler

Handler

Background

Thread B

Page 4: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

4

Learning Objectives in this Part of the Lesson• Know the motivations for Android

concurrency & concurrency frameworks

• Recognize the two types of Android concurrency frameworks, e.g.

• Handler, Messages, & Runnables(HaMeR) framework

• AsyncTask framework

See developer.android.com/reference/android/os/AsyncTask.html

Lo

op

er Message

Message

Message

Message

Message

Message

Queue

Message

UI Thread(main thread)

AsyncTask

Executor

Handler

Fu

ture

Ta

sk

Page 5: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

5

Overview of Android Concurrency

Frameworks

Page 6: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

6

• Android defines two primary concurrency frameworks

Overview of Android Concurrency Frameworks

Lo

op

er Message

Message

Message

Message

Message

Message

Queue

Message

UI Thread(main thread) AsyncTask

Executor

Runnable

Message

Background

Thread A

Handler

Handler

Background

Thread B

Page 7: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

7

• Android defines two primary concurrency frameworks

• Handlers, Messages, & Runnables(HaMeR)

Lo

op

er Message

Message

Message

Message

Message

Message

Queue

Message

Overview of Android Concurrency Frameworks

See developer.android.com/training/multiple-threads/communicate-ui.html

Operations running in one or more background threads can post/send

their results to the UI thread

UI Thread(main thread)

Runnable

Message

Background

Thread A

Handler

Handler

Background

Thread B

Page 8: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

8

• Android defines two primary concurrency frameworks

• Handlers, Messages, & Runnables(HaMeR)

• AsyncTask

Lo

op

er Message

Message

Message

Message

Message

Message

Queue

Message

Overview of Android Concurrency Frameworks

AsyncTask

ExecutorFu

ture

Ta

sk Handler

Operations run in one or more background threads & publish results to UI thread without manipulating threads,

handlers, messages, or runnables

UI Thread(main thread)

See developer.android.com/reference/android/os/AsyncTask.html

Page 9: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

9

• Both frameworks have pros &cons & are used extensivelythroughout Android

Overview of Android Concurrency Frameworks

See upcoming part on “Evaluating Android’s Concurrency Frameworks”

AsyncTask

PostingRunnables

SendingMessages

Usability(Simple)

+++ +++ ++

Usability(Complex)

+++ + ++

Scalability +++ + +

Flexibility ++ + +++

Efficiency ++ +++ +++

Page 10: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

10

Overview of Android Concurrency Frameworks

Long-duration & (potentially) blocking operations run in

background thread(s)

• Android’s concurrency frameworks are often used to decouple user interactions from computation & communication

Page 11: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

11

Overview of Android Concurrency FrameworksShort-duration, user-facing

operations run in the UI thread• Android’s concurrency frameworks are

often used to decouple user interactions from computation & communication

Page 12: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

12

Message

Queue

• Android’s concurrency frameworks are often used to decouple user interactions from computation & communication

Overview of Android Concurrency Frameworks

Lo

op

er Message

Message

Message

Message

Message

Message

UI Thread(main thread)

Runnable

Message

Background

Thread A

Handler

Handler

Background

Thread B

See github.com/douglascraigschmidt/POSA/tree/master/ex/M4/SimpleImageDownloads

Page 13: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

13

Background threads perform long-duration

image downloads

Message

Queue

• Android’s concurrency frameworks are often used to decouple user interactions from computation & communication

Overview of Android Concurrency Frameworks

Lo

op

er Message

Message

Message

Message

Message

Message

UI Thread(main thread)

Runnable

Message

Background

Thread A

Handler

Handler

Background

Thread B

Page 14: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

14

Message

Queue

• Android’s concurrency frameworks are often used to decouple user interactions from computation & communication

Overview of Android Concurrency Frameworks

Synchronized message queue passes results

from background thread(s) to UI thread

Lo

op

er Message

Message

Message

Message

Message

Message

UI Thread(main thread)

Runnable

Message

Background

Thread A

Handler

Handler

Background

Thread B

Page 15: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

15

• Android’s concurrency frameworks are often used to decouple user interactions from computation & communication

Overview of Android Concurrency Frameworks

UI thread displays the image to the user

Lo

op

er Message

Message

Message

Message

Message

Message

Queue

Message

UI Thread(main thread)

Runnable

Message

Background

Thread A

Handler

Handler

Background

Thread B

Page 16: Android Concurrency Frameworks: Introduction€¦ · 3 Learning Objectives in this Part of the Lesson •Know the motivations for Android concurrency & concurrency frameworks •Recognize

16

End of Android Concurrency Frameworks: Introduction