android concurrency frameworks: introduction€¦ · 3 learning objectives in this part of the...
TRANSCRIPT
Android Concurrency Frameworks:
Introduction
Douglas C. [email protected]
www.dre.vanderbilt.edu/~schmidt
Institute for Software
Integrated Systems
Vanderbilt University
Nashville, Tennessee, USA
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
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
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
5
Overview of Android Concurrency
Frameworks
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
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
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
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 ++ +++ +++
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
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
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
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
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
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
16
End of Android Concurrency Frameworks: Introduction