Android Concurrency & Synchronization: Introduction
Android Concurrency & Synchronization. D. C. Schmidt for Concurrent Software. See www.dre.vanderbilt.edu/~schmidt/PDF/BC-schmidt.pdf for more info ...
Android™ Concurrency
The Android Deep Dive Series is for intermediate and expert developers who use developer I saw a lot of concurrent code
Android Concurrency: The Active Object Pattern
Understand the Active Object pattern & how it's applied in Android See www.dre.vanderbilt.edu/~schmidt/PDF/ACE-concurrency.pdf for more info. Known Uses.
Android Concurrency & Synchronization: Part 6
Android Concurrency & Synchronization. D. C. Schmidt. 2. Async. Task. Learning Objectives in this Part of the Module. • Understand Android concurrency.
Android Concurrency: The Half-Sync/Half-Async Pattern (Part 1)
Android Concurrency: The Half-Sync/Half-Async Android Concurrency. Douglas C. Schmidt ... www.dre.vanderbilt.edu/~schmidt/PDF/HS-HA.pdf has more info ...
Sharing Objects - Java and Android Concurrency
git@bitbucket.org:spoto/java-and-android-concurrency-examples.git. Fausto Spoto The Heisenberg Principle of Concurrent Programming.
Android Concurrency & Synchronization: Part 4
Understand the Android mechanisms available to implement concurrent apps See www.dre.vanderbilt.edu/~schmidt/PDF/monitor.pdf for Monitor Object ...
nAdroid: Statically Detecting Ordering Violations in Android
Modern mobile applications use a hybrid concurrency model. In this model events are handled sequentially by event loop(s)
Programming Android
The Android Development Toolkit (ADT) Plug-in for Eclipse. Test Drive: Confirm That Your Installation Basic Multithreaded Concurrent Programming in Java.
Starfish: Efficient Concurrency Support for Computer Vision
We also report an implementation of Starfish on Android KitKat. Our work intercepts calls to OpenCV by replacing its C++ linked library with our own
Android Concurrency:
The Half
Sync/Half
AsyncPattern (Part 1)
Douglas C. Schmidt
d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidtInstitute for Software
Integrated Systems
Vanderbilt University
Nashville, Tennessee, USA
CS 282 Principles of Operating Systems II
Systems Programming for Android
Android Concurrency Douglas C. Schmidt
2Learning Objectives in this Part of the Module
•Understand the Half-Sync/Half-Async patternAndroid Concurrency Douglas C. Schmidt
3Challenge: Combining Sync & Async Processing
Context
•A concurrent system that performs both asynchronous & synchronous processing services that must communicate •The ThreadedDownload app a good example of this contextSocket
Socket
Downloads an image from
a server & displays itAndroid Concurrency Douglas C. Schmidt
4Problems
•Services that want the simplicity of synchronous processing shouldn't need to address the complexities of asynchronyChallenge: Combining Sync & Async Processing
Bitmap
downloadBitmap(String url) { InputStream is = (InputStream) new URL(url).getContent(); returnBitmapFactory.decodeStream
(is);Each thread needs to block independently to
prevent a flow-controlled connection from degrading the QoS that other clients receiveSocket
Socket
Android Concurrency Douglas C. Schmidt
5Problems
•Services that want the simplicity of synchronous processing shouldn't need to address the complexities of asynchrony •Synchronous & asynchronous processing services should be able to communicate without complicating their programming model or unduly degrading their performanceChallenge: Combining Sync & Async Processing
Background
Thread
1Background
Thread
nUI Thread
(main thread)Socket
Socket
Don't want to spawn an unbounded
number of background threads!Android Concurrency Douglas C. Schmidt
6UI Thread
Background
Thread
1Background
Thread
2Background
Thread
3BlockingQueue
AsyncTask
frameworkSolution
•Decompose the services in the system into two layers: synchronous & asynchronousChallenge: Combining Sync & Async Processing
UI Thread
Background
Thread
1Background
Thread
2MessageQueue
A bounded number of threads can be mapped to separate CPUs/cores to scale up performance via concurrencyBackground
Thread
3UI Thread
Looper
MyActivity
Android Concurrency Douglas C. Schmidt
7Solution
•Decompose the services in the system into two layers: synchronous & asynchronous •Add a queueing layer between them to mediate the communication between services in the asynchronous & synchronous layersChallenge: Combining Sync & Async Processing
UI Thread
Background
Thread
1Background
Thread
2Background
Thread
3BlockingQueue
AsyncTask
framework <UI Thread
Looper
MyActivity
Android Concurrency Douglas C. Schmidt
8Half-Sync/Half-Async POSA2 Concurrency
Intent
•Decouple asynchronous (async) & synchronous (sync) service processing in concurrent systems by introducing two intercommunicating layers - one for async & one for sync service processing - to simplify programming without unduly reducing performance www.dre.vanderbilt.edu/~schmidt/PDF/HS-HA.pdf has more infoAndroid Concurrency Douglas C. Schmidt
9Applicability
•When it's necessary to make performance efficient & scalable, while also ensuring that the use of concurrency simplifies - rather than complicates - programmingHalf-Sync/Half-Async POSA2 Concurrency
Android Concurrency Douglas C. Schmidt
10Applicability
•When it's necessary to make performance efficient & scalable, while also ensuring that the use of concurrency simplifies - rather than complicates - programming •When there are constraints on certain types of operations in certain contexts •e.g., short-duration vs. long-duration, blocking vs. non-blocking, etc.Half-Sync/Half-Async POSA2 Concurrency
This pattern is widely applied in operating systems & modern GUI frameworksAndroid Concurrency Douglas C. Schmidt
11Structure & Participants
Half-Sync/Half-Async POSA2 Concurrency
UI Thread
Android Concurrency Douglas C. Schmidt
12Structure & Participants
Half-Sync/Half-Async POSA2 Concurrency
Message
QueueAndroid Concurrency Douglas C. Schmidt
13Structure & Participants
Half-Sync/Half-Async POSA2 Concurrency
Background threads
Android Concurrency Douglas C. Schmidt
14Dynamics
Half-Sync/Half-Async POSA2 Concurrency
Event handling
runs reactively/ asynchronouslyAndroid Concurrency Douglas C. Schmidt
15Dynamics
Half-Sync/Half-Async POSA2 Concurrency
Queue requests
without blocking callerAndroid Concurrency Douglas C. Schmidt
16Dynamics
Half-Sync/Half-Async POSA2 Concurrency
Long-duration app processing
runs synchronously Sync services run concurrently, relative both to each other & to async servicesAndroid Concurrency Douglas C. Schmidt
17Consequences
+ Simplification & performance •Programming of higher-level sync processing services are simplified without degrading performance of lower-level system servicesHalf-Sync/Half-Async POSA2 Concurrency
AsyncTask
Executor
UI Thread
(main thread)Looper
Message
Message
Message
Message
Message
Message
QueueMessage
1. execute(url)
3. execute(future)
2. onPreExecute()
4. doInBackGround()
5. onProgressUpdate()
6. onPostExecute()
Handler
Android Concurrency Douglas C. Schmidt
18Consequences
+ Simplification & performance + Separation of concerns •Synchronization policies in each layer are decoupled so that each layer need not use the same concurrency strategiesHalf-Sync/Half-Async POSA2 Concurrency
AsyncTask
Executor
UI Thread
(main thread)Looper
Message
Message
Message
Message
Message
Message
QueueMessage
1. execute(url)
3. execute(future)
2. onPreExecute()
4. doInBackGround()
5. onProgressUpdate()
6. onPostExecute()
Handler
Android Concurrency Douglas C. Schmidt
19Consequences
+ Simplification & performance + Separation of concerns + Centralization of inter-layer communication •Inter-layer communication is centralized because all interaction is mediated by the queueing layerHalf-Sync/Half-Async POSA2 Concurrency
AsyncTask
Executor
UI Thread
(main thread)Looper
Message
Message
Message
Message
Message
Message
QueueMessage
1. execute(url)
3. execute(future)
2. onPreExecute()
4. doInBackGround()
5. onProgressUpdate()
6. onPostExecute()
Handler
Android Concurrency Douglas C. Schmidt
20Consequences
୧-crossing penalty •Arising from context switching, synchronization, & data copying overhead when data transferred between sync & async service layers via queueing layerHalf-Sync/Half-Async POSA2 Concurrency
AsyncTask
Executor
UI Thread
(main thread)Looper
Message
Message
Message
Message
Message
Message
QueueMessage
1. execute(url)
3. execute(future)
2. onPreExecute()
4. doInBackGround()
5. onProgressUpdate()
6. onPostExecute()
Handler
Android Concurrency Douglas C. Schmidt
21Consequences
୧-crossing penalty ୧-level app services may not benefit from async I/O •Depending on design of OS or app framework interfaces, higher-level services may not use low-level async I/O devices effectivelyHalf-Sync/Half-Async POSA2 Concurrency
AsyncTask
Executor
UI Thread
(main thread)Looper
Message
Message
Message
Message
Message
Message
QueueMessage
1. execute(url)
3. execute(future)
2. onPreExecute()
4. doInBackGround()
5. onProgressUpdate()
6. onPostExecute()
Handler
Android Concurrency Douglas C. Schmidt
22Consequences
୧-crossing penalty ୧-level app services may not benefit from async I/O •Apps can be hard to debug due to concurrent executionHalf-Sync/Half-Async POSA2 Concurrency
AsyncTask
Executor
UI Thread
(main thread)Looper
Message
Message
Message
Message
Message
Message
QueueMessage
1. execute(url)
3. execute(future)
2. onPreExecute()
4. doInBackGround()
5. onProgressUpdate()
6. onPostExecute()
Handler
Android Concurrency Douglas C. Schmidt
23Known Uses
•UNIX Networking SubsystemsHalf-Sync/Half-Async POSA2 Concurrency
www.dre.vanderbilt.edu/~schmidt/PDF/HS-HA.pdf has more infoAndroid Concurrency Douglas C. Schmidt
24Known Uses
•UNIX Networking Subsystems •Object Request Brokers (ORBs)Half-Sync/Half-Async POSA2 Concurrency
www.dre.vanderbilt.edu/~schmidt/PDF/OM-01.pdf has more infoORB Core
Object Adapter Object
(Servant) <POA Thread Pool
Socket Event Sources
IIOP Handlers & Acceptors
Reactor
Lane 3 Lane 2 Lane 1Android Concurrency Douglas C. Schmidt
25Known Uses
•UNIX Networking Subsystems •Object Request Brokers (ORBs) •Android AsyncTask frameworkHalf-Sync/Half-Async POSA2 Concurrency
AsyncTask
Executor
UI Thread
(main thread)Looper
Message
Message
Message
Message
Message
Message
QueueMessage
1. execute(url)
3. execute(future)
2. onPreExecute()
4. doInBackGround()
5. onProgressUpdate()
6. onPostExecute()
Handler
Android Concurrency Douglas C. Schmidt
26Summary
•This pattern separates concerns between the three layers, which makes concurrent software easier to understand, debug, & evolveAndroid Concurrency Douglas C. Schmidt
27Summary
•This pattern separates concerns between the three layers, which makes concurrent software easier to understand, debug, & evolvequotesdbs_dbs21.pdfusesText_27[PDF] android create id in xml
[PDF] android database best practices pdf
[PDF] android design patterns and best practices
[PDF] android design patterns and best practices pdf
[PDF] android design patterns book
[PDF] android design patterns example
[PDF] android design patterns interview questions
[PDF] android design patterns pdf
[PDF] android design patterns tutorial
[PDF] android developer fundamentals (version 2)
[PDF] android developer fundamentals (version 2) pdf
[PDF] android developer fundamentals course practicals pdf
[PDF] android developer fundamentals course concept reference
[PDF] android developer fundamentals course (version 2)