[PDF] Android Concurrency: The Half-Sync/Half-Async Pattern (Part 1)





Previous PDF Next PDF



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

Async

Pattern (Part 1)

Douglas C. Schmidt

d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/~schmidt

Institute 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

2

Learning Objectives in this Part of the Module

•Understand the Half-Sync/Half-Async pattern

Android Concurrency Douglas C. Schmidt

3

Challenge: 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 context

Socket

Socket

Downloads an image from

a server & displays it

Android Concurrency Douglas C. Schmidt

4

Problems

•Services that want the simplicity of synchronous processing shouldn't need to address the complexities of asynchrony

Challenge: Combining Sync & Async Processing

Bitmap

downloadBitmap(String url) { InputStream is = (InputStream) new URL(url).getContent(); return

BitmapFactory.decodeStream

(is);

Each thread needs to block independently to

prevent a flow-controlled connection from degrading the QoS that other clients receive

Socket

Socket

Android Concurrency Douglas C. Schmidt

5

Problems

•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 performance

Challenge: Combining Sync & Async Processing

Background

Thread

1

Background

Thread

n

UI Thread

(main thread)

Socket

Socket

Don't want to spawn an unbounded

number of background threads!

Android Concurrency Douglas C. Schmidt

6

UI Thread

Background

Thread

1

Background

Thread

2

Background

Thread

3

BlockingQueue

AsyncTask

framework

Solution

•Decompose the services in the system into two layers: synchronous & asynchronous

Challenge: Combining Sync & Async Processing

UI Thread

Background

Thread

1

Background

Thread

2

MessageQueue

A bounded number of threads can be mapped to separate CPUs/cores to scale up performance via concurrency

Background

Thread

3

UI Thread

Looper

MyActivity

Android Concurrency Douglas C. Schmidt

7

Solution

•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 layers

Challenge: Combining Sync & Async Processing

UI Thread

Background

Thread

1

Background

Thread

2

Background

Thread

3

BlockingQueue

AsyncTask

framework <> <> <> <> <> <>

UI Thread

Looper

MyActivity

Android Concurrency Douglas C. Schmidt

8

Half-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 info

Android Concurrency Douglas C. Schmidt

9

Applicability

•When it's necessary to make performance efficient & scalable, while also ensuring that the use of concurrency simplifies - rather than complicates - programming

Half-Sync/Half-Async POSA2 Concurrency

Android Concurrency Douglas C. Schmidt

10

Applicability

•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 frameworks

Android Concurrency Douglas C. Schmidt

11

Structure & Participants

Half-Sync/Half-Async POSA2 Concurrency

UI Thread

Android Concurrency Douglas C. Schmidt

12

Structure & Participants

Half-Sync/Half-Async POSA2 Concurrency

Message

Queue

Android Concurrency Douglas C. Schmidt

13

Structure & Participants

Half-Sync/Half-Async POSA2 Concurrency

Background threads

Android Concurrency Douglas C. Schmidt

14

Dynamics

Half-Sync/Half-Async POSA2 Concurrency

Event handling

runs reactively/ asynchronously

Android Concurrency Douglas C. Schmidt

15

Dynamics

Half-Sync/Half-Async POSA2 Concurrency

Queue requests

without blocking caller

Android Concurrency Douglas C. Schmidt

16

Dynamics

Half-Sync/Half-Async POSA2 Concurrency

Long-duration app processing

runs synchronously Sync services run concurrently, relative both to each other & to async services

Android Concurrency Douglas C. Schmidt

17

Consequences

+ Simplification & performance •Programming of higher-level sync processing services are simplified without degrading performance of lower-level system services

Half-Sync/Half-Async POSA2 Concurrency

AsyncTask

Executor

UI Thread

(main thread)

Looper

Message

Message

Message

Message

Message

Message

Queue

Message

1. execute(url)

3. execute(future)

2. onPreExecute()

4. doInBackGround()

5. onProgressUpdate()

6. onPostExecute()

Handler

Android Concurrency Douglas C. Schmidt

18

Consequences

+ Simplification & performance + Separation of concerns •Synchronization policies in each layer are decoupled so that each layer need not use the same concurrency strategies

Half-Sync/Half-Async POSA2 Concurrency

AsyncTask

Executor

UI Thread

(main thread)

Looper

Message

Message

Message

Message

Message

Message

Queue

Message

1. execute(url)

3. execute(future)

2. onPreExecute()

4. doInBackGround()

5. onProgressUpdate()

6. onPostExecute()

Handler

Android Concurrency Douglas C. Schmidt

19

Consequences

+ Simplification & performance + Separation of concerns + Centralization of inter-layer communication •Inter-layer communication is centralized because all interaction is mediated by the queueing layer

Half-Sync/Half-Async POSA2 Concurrency

AsyncTask

Executor

UI Thread

(main thread)

Looper

Message

Message

Message

Message

Message

Message

Queue

Message

1. execute(url)

3. execute(future)

2. onPreExecute()

4. doInBackGround()

5. onProgressUpdate()

6. onPostExecute()

Handler

Android Concurrency Douglas C. Schmidt

20

Consequences

୧-crossing penalty •Arising from context switching, synchronization, & data copying overhead when data transferred between sync & async service layers via queueing layer

Half-Sync/Half-Async POSA2 Concurrency

AsyncTask

Executor

UI Thread

(main thread)

Looper

Message

Message

Message

Message

Message

Message

Queue

Message

1. execute(url)

3. execute(future)

2. onPreExecute()

4. doInBackGround()

5. onProgressUpdate()

6. onPostExecute()

Handler

Android Concurrency Douglas C. Schmidt

21

Consequences

୧-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 effectively

Half-Sync/Half-Async POSA2 Concurrency

AsyncTask

Executor

UI Thread

(main thread)

Looper

Message

Message

Message

Message

Message

Message

Queue

Message

1. execute(url)

3. execute(future)

2. onPreExecute()

4. doInBackGround()

5. onProgressUpdate()

6. onPostExecute()

Handler

Android Concurrency Douglas C. Schmidt

22

Consequences

୧-crossing penalty ୧-level app services may not benefit from async I/O •Apps can be hard to debug due to concurrent execution

Half-Sync/Half-Async POSA2 Concurrency

AsyncTask

Executor

UI Thread

(main thread)

Looper

Message

Message

Message

Message

Message

Message

Queue

Message

1. execute(url)

3. execute(future)

2. onPreExecute()

4. doInBackGround()

5. onProgressUpdate()

6. onPostExecute()

Handler

Android Concurrency Douglas C. Schmidt

23

Known Uses

•UNIX Networking Subsystems

Half-Sync/Half-Async POSA2 Concurrency

www.dre.vanderbilt.edu/~schmidt/PDF/HS-HA.pdf has more info

Android Concurrency Douglas C. Schmidt

24

Known 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 info

ORB Core

Object Adapter Object

(Servant) <>

POA Thread Pool

Socket Event Sources

IIOP Handlers & Acceptors

Reactor

Lane 3 Lane 2 Lane 1

Android Concurrency Douglas C. Schmidt

25

Known Uses

•UNIX Networking Subsystems •Object Request Brokers (ORBs) •Android AsyncTask framework

Half-Sync/Half-Async POSA2 Concurrency

AsyncTask

Executor

UI Thread

(main thread)

Looper

Message

Message

Message

Message

Message

Message

Queue

Message

1. execute(url)

3. execute(future)

2. onPreExecute()

4. doInBackGround()

5. onProgressUpdate()

6. onPostExecute()

Handler

Android Concurrency Douglas C. Schmidt

26

Summary

•This pattern separates concerns between the three layers, which makes concurrent software easier to understand, debug, & evolve

Android Concurrency Douglas C. Schmidt

27

Summary

•This pattern separates concerns between the three layers, which makes concurrent software easier to understand, debug, & evolvequotesdbs_dbs21.pdfusesText_27
[PDF] android cookbook 2019

[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)