Index

A

abstractions, programming languages as, 3

accepting loader events (listing 4.18), 62

account type

definition (listing 7.6), 144

in sync-adapters, 143144

Activities

in application model, 3031

AsyncTask errors, 5558

Services versus, 9293

addOnFileDescriptorEventListener method, 86

administrative fields in Messages, 8183

AIDL (Android Interface Definition Language), 120123

AlarmManager, scheduling tasks with IntentService, 134142

AlarmManagerService, 135139

constraints on schedulable tasks, 139142

AlarmManagerService, 135139

Android applications. See applications

Android Interface Definition Language (AIDL), 120123

Android model, web apps versus desktop apps, 6768

Android Studio

Findbugs, 169175

static analysis tools, 168169

annotations, 177

JCIP annotations, 177178

support library annotations, 178179

applications

component lifecycles, 2931, 3334

creating processes, 123125

definition, 30

main thread, 36

process priority, 3133

restrictions on, 29

startup, 3638

web applications versus, 35

assertions, 179180

asynchronous execution

AsyncTasks. See AsyncTasks

with closures, 4145

cursor loaders, 5966

with loopers. See Looper/Handler framework

asynchronous messages, 87

AsyncTasks, 41

completion, 5052

cursor loaders and, 5966

doInBackground method, 4548

errors

concurrency errors, 5255

lifecycle errors, 5558

execution, 4849

as Services, 99101

when to use

autonomous tasks, 59

cancellable tasks, 59

atomic execution, 56. See also synchronization

single-threaded UIs, 39

volatile keyword, 19

autonomous tasks, AsyncTasks as, 59

B

background execution. See asynchronous execution

best practices for concurrency, 180181

Binders, 113, 125

data transfer limits, 126

process failure, reporting, 126

threads, 125

@BinderThread annotation, 178

binding

multiple Services, 107108

Services, 105

bindService method, 104

bound Services, 9596, 103104

binding, 105

binding multiple Services, 107108

flags, 111112

local bound Services, 112114

unbinding, 106107

bulk inserts

initial example (listing 4.8), 51

interruptible (listing 4.9), 5152

C

callbacks, futures versus, 2627

cancelable tasks, AsyncTasks as, 59

canceling AsyncTasks, 5052

cellular radio power management, 129130

classes

Messenger, 116119

Thread, 1011

Timer, 130

TimerTask, 130

clock type in scheduling tasks, 136

Cloneable interface, 99

closures, 4145

clustering tasks, 129130

Collections.unmodifiable method, 54

communication. See inter-process communication (IPC)

completion of AsyncTasks, 5052

components

lifecycles of, 2931, 3334

AsyncTask errors, 5558

list of, 2930

concurrency

AsyncTask errors, 5255

atomic execution, 56

best practices, 180181

difficulty of, 1

in hardware, 34

illusion of sequential execution, 67

sequential execution versus, 4

in software

functional programming languages, 23

languages as contracts, 3

procedural programming languages, 2

threads, 45. See also threads

Concurrency package, 23

content authority in sync-adapters, 143

content provider definition

listing 7.7, 144

listing 7.13, 152

ContentProvider, 143

contracts

binding Services, 105

maintaining sequential execution illusion, 67

programming languages as, 3

copy-on-write memory sharing, 3638

createFromParcel method, 116

cross-task communication (listing 4.7), 49

cursor loaders, 5966

custom service-based schedulers, 133

D

data transfer limits for Binders, 126

database query

with anonymous class (listing 4.4), 44

initial example (listing 4.1), 4142

dataset change notification

initial example (listing 7.14), 154

for sync-adapters (listing 7.15), 155

deadlock, 1617, 3839

declaring Services (listing 6.1), 92

defining sync-adapters, 143145

delayed animation

improved example (listing 5.2), 7576

initial example (listing 5.1), 74

messaged example (listing 5.3), 7980

dependency injection frameworks, 141

desktop applications versus web apps in Android model, 6768

doInBackground method, 4548, 100

E

effective immutability, 23

enqueueing Messages in Looper/Handler framework, 78

Enterprise Android (Mednieks, et al.), 143

epoll mechanism, 86

errors

in AsyncTasks

concurrency errors, 5255

lifecycle errors, 5558

in synchronization, 1517

exclusion files, 177

execution

of AsyncTasks, 4849

atomic execution. See atomic execution

executors

futures, 2627

optimum number of threads, 2526

explicit Intents, 9697

F

fields in Messages, 81

administrative fields, 8183

messaging fields, 83

remote fields, 84

Findbugs, 169

with Android Studio, 169175

with Gradle, 175177

“The First Draft Report on the EDVAC” (von Neumann), 1

flag field (Messages), 83

flags on bound Services, 111112

flash memory, limitations, 29

functional programming languages, 23

functions, passing closures to (listing 4.3), 43

futures

callbacks versus, 2627

definition, 26

G

garbage collection, process reaping versus, 34

Göetz, Brian, 9, 21

Gradle, 175177

Grigorik, Ilya, 130

@GuardedBy annotation, 178

H

Handler framework. See Looper/Handler framework

hardware, concurrency in, 34

High Performance Browser Networking (Grigorik), 130

hints. See annotations

hybrid services, 93, 153

I

idealistic backgrounding (listing 4.2), 42

IllegalMonitorStateException (listing 2.13), 21

@Immutable annotation, 178

immutable data, sharing between threads, 23

implicit Intents, 9798

initializing

loaders (listing 4.17), 61

threads as loopers, 84

inner class implementation (listing 4.15), 57

Inspections in Android Studio, 168169

intent filters, 97

Intents, 9699

in application model, 3031

explicit Intents, 9697

implicit Intents, 9798

IntentService, 99103

scheduling tasks with AlarmManager, 134142

AlarmManagerService, 135139

constraints on schedulable tasks, 139142

interfaces

Cloneable, 99

Parcelable, 99, 116

Runnable, 11, 7377

Serializable, 99

inter-process communication (IPC), 114115

AIDL, 120123

Messenger class, 116119

optimizing, 112114

Parcelable interface, 116

interruptions, 21

bulk inserts, 5152

flag state, 51

to started Services, 9495

IPC (inter-process communication). See inter-process communication (IPC)

isCancelled method, 5052

isIdle method, 86

J

Java Concurrency in Practice (Göetz and Peierls, et al), 9, 23, 177178

JCIP annotations, 177178

JobSchedule Service (listing 7.16), 156

JobScheduler, 155165

implementing tasks, 161165

running tasks, 159161

scoring, 165

K

keywords

synchronized, 12, 1415

this, 13

volatile, 1720

killing processes, 33

L

LARGE_TASK_EXECUTOR, 49

lifecycle awareness in task scheduling, 128

lifecycles

AsyncTask errors, 5558

of components, 2931, 3334

process priority, 3133

of Services, 109111

linkToDeath method, 126

listings

accepting loader events, 62

account type definition, 144

AIDL definition, 120

AIDL-generated code, 120122

Alarm Scheduler task execution, 140

Android support annotations, 179

AsyncTask Service, 100

AsyncTasks

concurrency errors, 52, 53, 54

execution, 48

initial example, 46

lifecycle errors, 56

local copies of mutable data structures, 5455

binding multiple Services to single Context, 108

bound Service client, 103104

bulk inserts

initial example, 51

interruptible, 5152

content provider definition, 144, 152

cursor loaders

complete, 6566

creating, 63

database query

with anonymous class, 44

initial example, 4142

dataset change notification

initial example, 154

for sync-adapters, 155

deadlock, 17

declaring Services, 92

delayed animation

improved example, 7576

initial example, 74

messaged example, 7980

explicit Intents, 9697

Findbugs

failure example, 174175

filter, 177

in Gradle, 176

successful example, 173

idealistic backgrounding, 42

IllegalMonitorStateException, 21

incorrect cross-task communication, 49

incorrect synchronization (single thread), 1718

incorrect volatile usage, 20

initializing loaders, 61

inner class implementation, 57

IntentFilter, 97

IntentService helper method, 102103

JobSchedule Service, 156

JobScheduler tasks

implementing, 161163

scheduling, 157158

local Service, 112113

local Service client, 113

looper creation

with handler, 85

initial example, 84

without race condition, 85

low-power periodic scheduling with AlarmManager, 137138

managed object implementation, 122123

manifest for low-power scheduler, 138

message enqueueing, 82

Messenger Service, 118119

Messenger usage, 117118

minimal bound Service, 109

mutex errors, 16

passing closures to functions, 43

periodic Looper task, 131132

periodic scheduling with AlarmManager, 134

reentrant monitors, 15

remote managed object usage, 123

safe publication, 2425

Service injection, 114

simple account creation, 150151

singleton bound Service, 111

skeleton Android application, 67

skeleton cursor list activity, 60

skeleton Java application, 67

spawning threads, 10

specifying component’s process, 124, 125

sync-adapter service

complete service, 148

implementation, 148149

initial example, 145

sync-adapters

definition, 143

implementation, 149150

synchronized methods, 14

synchronized static methods, 1415

synchronizing on objects, 12

synchronizing on this, 13

threads with Runnable, 11

volatile keyword, 19

wait and notify methods, 22

loaders, 5966

local bound Services, 112114

local processes, 124

locks, definition, 12. See also mutexes

loop method, 71

Looper/Handler framework, 6971

Java classes in, 71

main thread as looper, 3839, 74

Messages

administrative fields, 8183

enqueueing, 78

fields in, 81

messaging fields, 83

remote fields, 84

method overloading, 7880

native Looper, 86

Runnable interface, posting, 7377

safe publication, 6970

scheduling tasks, 130133

starting loopers, 8486

sync-barriers, 8788

task execution example, 7173

M

main thread, 9, 36

as looper, 3839, 74

@MainThread annotation, 178

marshaling, 99

McCarthy, John, 23

McLuhan, Marshall, 167

memory leaks, 80

memory model, 7

copy-on-write memory sharing, 3638

MessageQueue, 70

native Looper, 86

sync-barriers, 8788

task execution example, 7173

MessageQueue.addOnFileDescriptorEventListener method, 86

MessageQueue.isIdle method, 86

MessageQueue.postSyncBarrier method, 87

MessageQueue.removeOnFileDescriptorEventListener method, 86

MessageQueue.removeSyncBarrier method, 88

Messages

enqueueing in Looper/Handler framework, 78

fields in, 81

administrative fields, 8183

messaging fields, 83

remote fields, 84

method overloading and, 7880

Message.setAsynchronous method, 87

messaging fields in Messages, 83

Messenger class, 116119

methods

addOnFileDescriptorEventListener, 86

bindService, 104

createFromParcel, 116

doInBackground, 4548, 100

isCancelled, 5052

isIdle, 86

linkToDeath, 126

loop, 71

notify, 2223

notifyAll, 2223

onBind, 95, 104, 105

onCancelled, 50

onConnected, 95

onCreate, 74

onHandleIntent, 101

onPause, 7677

onPostExecute, 47, 50

onProgressUpdate, 47

onServiceConnected, 105

onStartCommand, 9395, 100101

overloading, 7880

postSyncBarrier, 87

publishProgress, 47

removeOnFileDescriptorEventListener, 86

removeSyncBarrier, 88

run, 7677

setAsynchronous, 87

stopSelf, 101

stopService, 101

synchronized, 1415

unbindService, 104, 106107

unmodifiable, 54

wait, 2021

writeToParcel, 116

minimal bound Service (listing 6.10), 109

model-view-controller (MVC) pattern, deadlock, 3839

monitors. See also mutexes

definition, 12

reentrant monitors, 15

Moore’s law, 23

multiple Services, binding, 107108

Murphy, Mark, 59

mutable data

local copies of, 54

sharing between threads, 2325

mutating state, 2

mutexes, 6

definition, 12

errors in, 1516

example usage, 1213

reentrant monitors, 15

synchronized methods, 1415

this keyword, 13

wait method, 2021

MVC (model-view-controller) pattern, deadlock, 3839

N

native Looper, 86

notify method, 2223

notifyAll method, 2223

@NotThreadSafe annotation, 178

O

onBind method, 95, 104, 105

onCancelled method, 50

onConnected method, 95

onCreate method, 74

onHandleIntent method, 101

onPause method, 7677

onPostExecute method, 47, 50

onProgressUpdate method, 47

onServiceConnected method, 105

onStartCommand method, 9395, 100101

oom_adj attribute, 3132

oom_score_adj attribute, 32

opportunistic suspension, 129

optimizing IPC (inter-process communication), 112114

optimum number of threads, 2526

overloading methods, 7880

P

packages, Concurrency, 23

Parcelable interface, 99, 116

passing closures to functions (listing 4.3), 43

PendingIntents, 135

periodic tasks. See scheduling tasks

posting Runnable interface in Looper/Handler framework, 7377

postSyncBarrier method, 87

power usage in task scheduling, 129130

priority of processes. See process priority

procedural programming languages, 2

process priority, 3133

flags on bound Services, 111112

for Services, 93

in task scheduling, 128129

process reaping, garbage collection versus, 34

processes

creating, 123125

inter-process communication (IPC), 114115

AIDL, 120123

Messenger class, 116119

optimizing, 112114

Parcelable interface, 116

local, 124

remote, 124

reporting failure, 126

terminating, 33

programming languages

as contracts, 3

functional, 23

illusion of sequential execution, 67

procedural, 2

proxies, 115

publishProgress method, 47

R

race conditions, 13, 77

Receivers in application model, 3031

reentrant monitors, 15

remote fields in Messages, 84

remote processes, 124

removeOnFileDescriptorEventListener method, 86

removeSyncBarrier method, 88

run method, 10, 7677

Runnable interface, 11, 7377

running

JobScheduler tasks, 159161

sync-adapters, 145147, 153154

runtime concurrency checks, 179180

S

safe publication, 2325, 6970

scheduling tasks

AlarmManager and IntentService, 134142

AlarmManagerService, 135139

constraints on schedulable tasks, 139142

characteristics of, 127128

lifecycle awareness, 128

power usage, 129130

process priority, 128129

scorecard for, 130

thread safety, 128

custom service-based schedulers, 133

JobScheduler, 155165

implementing tasks, 161165

running tasks, 159161

scoring, 165

Looper/Handler framework, 130133

sync-adapters, 142155

defining, 143145

implementing, 147152

running, 145147, 153154

scoring, 152155

sync-barriers and, 8788

Timer and TimerTask classes, 130

scheduling window size in scheduling tasks, 136

scorecard (task scheduling characteristics), 130

AlarmManager and IntentService, 141

custom service-based schedulers, 133

JobScheduler, 165

Looper/Handler framework, 132

sync-adapters, 155

Timer and TimerTask classes, 130

sequential execution

concurrency versus, 4

hardware versus software, 34

illusion of, 67

SERIAL_EXECUTOR, 48

Serializable interface, 99

Service injection (listing 6.14), 114

Services

Activities versus, 9293

AlarmManagerService, 135139

AsyncTasks as, 99101

bound Services, 9596, 103104

binding, 105

binding multiple Services, 107108

flags, 111112

local bound Services, 112114

unbinding, 106107

custom service-based schedulers, 133

hybrid services, 93, 153

Intents, 9699

explicit Intents, 9697

implicit Intents, 9798

IntentService, 99103

scheduling tasks with AlarmManager, 134142

JobSchedule Service (listing 7.16), 156

lifecycle of, 109111

process failure, reporting, 126

process priority, 32

started Services, 9395

when to use, 91

setAsynchronous method, 87

sharing

data between threads, 2325

memory, 3638

single-threaded UIs, 3839

singleton bound Service (listing 6.11), 111

singletons, 106

software, concurrency in

functional programming languages, 23

languages as contracts, 3

procedural programming languages, 2

spawning threads (listing 2.1), 10

start method, Thread class, 10

started Services, 9395

starting

applications, 3638

loopers, 8486

starving threads, 19

static analysis tools, 167168

Android Studio, 168169

Findbugs, 169

with Android Studio, 169175

with Gradle, 175177

static methods, 1415

stopSelf method, 101

stopService method, 101

stubs, 115

support library annotations, 178179

switched messages, 83

sync-adapters, 142155

defining, 143145

implementing, 147152

running, 145147, 153154

scoring, 152155

sync-barriers, 8788

synchronization, 6, 11

errors, 1517

mutexes

definition, 12

example usage, 1213

reentrant monitors, 15

synchronized methods, 1415

this keyword, 13

notify and notifyAll methods, 2223

volatile keyword, 1720

wait method, 2021

synchronized keyword, 12, 1415

T

target field (Messages), 82

task clustering, 129130

task scheduling. See scheduling tasks

terminating processes, 33

this keyword, 13

Thread class, 1011

thread safety in task scheduling, 128

THREAD_POOL_EXECUTOR, 4849

threads, 45

asynchronous execution with closures, 4145

atomic execution, 56

Binder threads, 125

executors

futures, 2627

optimum number of threads, 2526

initializing as loopers, 84

interruptions, 51

main thread, 9, 36

as looper, 3839, 74

Runnable interface, 11

sharing data, safe publication, 2325

synchronization, 11

errors, 1517

mutex usage, 1213

notify and notifyAll methods, 2223

reentrant monitors, 15

synchronized methods, 1415

this keyword, 13

volatile keyword, 1720

wait method, 2021

Thread class, 1011

@ThreadSafe annotation, 178

timed-wait, 86

Timer class, 130

TimerTask class, 130

tools

annotations, 177

JCIP annotations, 177178

support library annotations, 178179

assertions, 179180

static analysis, 167168

Android Studio, 168169

Findbugs, 169177

type-safe templates, 45

U

UI thread, 9, 36

as looper, 3839, 74

@UIThread annotation, 178

unbinding Services, 106107

unbindService method, 104, 106107

unmarshaling, 99

unmodifiable method, 54

Updike, John, 41

V

varargs, 47

visibility, 1720

volatile keyword, 1720

von Neumann, John, 1

W

wait method, 2021

wake-locks, 129, 137, 138139

weak references, 5758

web applications

Android applications versus, 35

in Android model, 6768

when field (Messages), 82

Whyte, William H., 127

@WorkerThread annotation, 178

writeToParcel method, 116

Y

Yegge, Steve, 106

Z

Zygote, 3638

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.244.67