abstractions, programming languages as, 3
accepting loader events (listing 4.18), 62
account type
definition (listing 7.6), 144
Activities
addOnFileDescriptorEventListener method, 86
administrative fields in Messages, 81–83
AIDL (Android Interface Definition Language), 120–123
AlarmManager, scheduling tasks with IntentService, 134–142
constraints on schedulable tasks, 139–142
Android applications. See applications
Android Interface Definition Language (AIDL), 120–123
Android model, web apps versus desktop apps, 67–68
Android Studio
static analysis tools, 168–169
annotations, 177
support library annotations, 178–179
component lifecycles, 29–31, 33–34
definition, 30
main thread, 36
restrictions on, 29
web applications versus, 35
AsyncTasks. See AsyncTasks
with loopers. See Looper/Handler framework
asynchronous messages, 87
AsyncTasks, 41
errors
when to use
autonomous tasks, 59
cancellable tasks, 59
atomic execution, 5–6. See also synchronization
single-threaded UIs, 39
volatile keyword, 19
autonomous tasks, AsyncTasks as, 59
background execution. See asynchronous execution
best practices for concurrency, 180–181
data transfer limits, 126
process failure, reporting, 126
threads, 125
@BinderThread annotation, 178
binding
Services, 105
bindService method, 104
bound Services, 95–96, 103–104
binding, 105
binding multiple Services, 107–108
bulk inserts
initial example (listing 4.8), 51
interruptible (listing 4.9), 51–52
callbacks, futures versus, 26–27
cancelable tasks, AsyncTasks as, 59
cellular radio power management, 129–130
classes
Timer, 130
TimerTask, 130
clock type in scheduling tasks, 136
Cloneable interface, 99
Collections.unmodifiable method, 54
communication. See inter-process communication (IPC)
completion of AsyncTasks, 50–52
components
concurrency
difficulty of, 1
illusion of sequential execution, 6–7
sequential execution versus, 4
in software
functional programming languages, 2–3
languages as contracts, 3
procedural programming languages, 2
threads, 4–5. 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, 6–7
programming languages as, 3
copy-on-write memory sharing, 36–38
createFromParcel method, 116
cross-task communication (listing 4.7), 49
custom service-based schedulers, 133
data transfer limits for Binders, 126
database query
with anonymous class (listing 4.4), 44
initial example (listing 4.1), 41–42
dataset change notification
initial example (listing 7.14), 154
for sync-adapters (listing 7.15), 155
declaring Services (listing 6.1), 92
defining sync-adapters, 143–145
delayed animation
improved example (listing 5.2), 75–76
initial example (listing 5.1), 74
messaged example (listing 5.3), 79–80
dependency injection frameworks, 141
desktop applications versus web apps in Android model, 67–68
doInBackground method, 45–48, 100
effective immutability, 23
enqueueing Messages in Looper/Handler framework, 78
Enterprise Android (Mednieks, et al.), 143
epoll mechanism, 86
errors
in AsyncTasks
exclusion files, 177
execution
atomic execution. See atomic execution
executors
optimum number of threads, 25–26
fields in Messages, 81
messaging fields, 83
remote fields, 84
Findbugs, 169
“The First Draft Report on the EDVAC” (von Neumann), 1
flag field (Messages), 83
flags on bound Services, 111–112
flash memory, limitations, 29
functional programming languages, 2–3
functions, passing closures to (listing 4.3), 43
futures
definition, 26
garbage collection, process reaping versus, 34
Grigorik, Ilya, 130
@GuardedBy annotation, 178
Handler framework. See Looper/Handler framework
High Performance Browser Networking (Grigorik), 130
hints. See annotations
idealistic backgrounding (listing 4.2), 42
IllegalMonitorStateException (listing 2.13), 21
@Immutable annotation, 178
immutable data, sharing between threads, 23
initializing
loaders (listing 4.17), 61
threads as loopers, 84
inner class implementation (listing 4.15), 57
Inspections in Android Studio, 168–169
intent filters, 97
scheduling tasks with AlarmManager, 134–142
constraints on schedulable tasks, 139–142
interfaces
Cloneable, 99
Serializable, 99
inter-process communication (IPC), 114–115
Parcelable interface, 116
interruptions, 21
flag state, 51
IPC (inter-process communication). See inter-process communication (IPC)
isIdle method, 86
Java Concurrency in Practice (Göetz and Peierls, et al), 9, 23, 177–178
JobSchedule Service (listing 7.16), 156
scoring, 165
keywords
this, 13
killing processes, 33
LARGE_TASK_EXECUTOR, 49
lifecycle awareness in task scheduling, 128
lifecycles
linkToDeath method, 126
listings
accepting loader events, 62
account type definition, 144
AIDL definition, 120
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, 54–55
binding multiple Services to single Context, 108
bulk inserts
initial example, 51
content provider definition, 144, 152
cursor loaders
creating, 63
database query
with anonymous class, 44
dataset change notification
initial example, 154
for sync-adapters, 155
deadlock, 17
declaring Services, 92
delayed animation
initial example, 74
Findbugs
filter, 177
in Gradle, 176
successful example, 173
idealistic backgrounding, 42
IllegalMonitorStateException, 21
incorrect cross-task communication, 49
incorrect synchronization (single thread), 17–18
incorrect volatile usage, 20
initializing loaders, 61
inner class implementation, 57
IntentFilter, 97
IntentService helper method, 102–103
JobSchedule Service, 156
JobScheduler tasks
local Service client, 113
looper creation
with handler, 85
initial example, 84
without race condition, 85
low-power periodic scheduling with AlarmManager, 137–138
managed object implementation, 122–123
manifest for low-power scheduler, 138
message enqueueing, 82
minimal bound Service, 109
mutex errors, 16
passing closures to functions, 43
periodic scheduling with AlarmManager, 134
reentrant monitors, 15
remote managed object usage, 123
Service injection, 114
simple account creation, 150–151
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
initial example, 145
sync-adapters
definition, 143
synchronized methods, 14
synchronized static methods, 14–15
synchronizing on objects, 12
synchronizing on this, 13
threads with Runnable, 11
volatile keyword, 19
wait and notify methods, 22
local processes, 124
locks, definition, 12. See also mutexes
loop method, 71
Looper/Handler framework, 69–71
Java classes in, 71
main thread as looper, 38–39, 74
Messages
enqueueing, 78
fields in, 81
messaging fields, 83
remote fields, 84
native Looper, 86
Runnable interface, posting, 73–77
@MainThread annotation, 178
marshaling, 99
McLuhan, Marshall, 167
memory leaks, 80
memory model, 7
copy-on-write memory sharing, 36–38
MessageQueue, 70
native Looper, 86
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
messaging fields, 83
remote fields, 84
Message.setAsynchronous method, 87
messaging fields in Messages, 83
methods
addOnFileDescriptorEventListener, 86
bindService, 104
createFromParcel, 116
isIdle, 86
linkToDeath, 126
loop, 71
onCancelled, 50
onConnected, 95
onCreate, 74
onHandleIntent, 101
onProgressUpdate, 47
onServiceConnected, 105
onStartCommand, 93–95, 100–101
postSyncBarrier, 87
publishProgress, 47
removeOnFileDescriptorEventListener, 86
removeSyncBarrier, 88
setAsynchronous, 87
stopSelf, 101
stopService, 101
unmodifiable, 54
writeToParcel, 116
minimal bound Service (listing 6.10), 109
model-view-controller (MVC) pattern, deadlock, 38–39
monitors. See also mutexes
definition, 12
reentrant monitors, 15
multiple Services, binding, 107–108
Murphy, Mark, 59
mutable data
local copies of, 54
sharing between threads, 23–25
mutating state, 2
mutexes, 6
definition, 12
reentrant monitors, 15
this keyword, 13
MVC (model-view-controller) pattern, deadlock, 38–39
native Looper, 86
@NotThreadSafe annotation, 178
onCancelled method, 50
onConnected method, 95
onCreate method, 74
onHandleIntent method, 101
onProgressUpdate method, 47
onServiceConnected method, 105
onStartCommand method, 93–95, 100–101
oom_score_adj attribute, 32
opportunistic suspension, 129
optimizing IPC (inter-process communication), 112–114
optimum number of threads, 25–26
packages, Concurrency, 23
passing closures to functions (listing 4.3), 43
PendingIntents, 135
periodic tasks. See scheduling tasks
posting Runnable interface in Looper/Handler framework, 73–77
postSyncBarrier method, 87
power usage in task scheduling, 129–130
priority of processes. See process priority
procedural programming languages, 2
flags on bound Services, 111–112
for Services, 93
process reaping, garbage collection versus, 34
processes
inter-process communication (IPC), 114–115
Parcelable interface, 116
local, 124
remote, 124
reporting failure, 126
terminating, 33
programming languages
as contracts, 3
illusion of sequential execution, 6–7
procedural, 2
proxies, 115
publishProgress method, 47
Receivers in application model, 30–31
reentrant monitors, 15
remote fields in Messages, 84
remote processes, 124
removeOnFileDescriptorEventListener method, 86
removeSyncBarrier method, 88
running
sync-adapters, 145–147, 153–154
runtime concurrency checks, 179–180
safe publication, 23–25, 69–70
AlarmManager and IntentService, 134–142
constraints on schedulable tasks, 139–142
lifecycle awareness, 128
scorecard for, 130
thread safety, 128
custom service-based schedulers, 133
scoring, 165
Looper/Handler framework, 130–133
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
SERIAL_EXECUTOR, 48
Serializable interface, 99
Service injection (listing 6.14), 114
Services
bound Services, 95–96, 103–104
binding, 105
binding multiple Services, 107–108
custom service-based schedulers, 133
scheduling tasks with AlarmManager, 134–142
JobSchedule Service (listing 7.16), 156
process failure, reporting, 126
process priority, 32
when to use, 91
setAsynchronous method, 87
sharing
singleton bound Service (listing 6.11), 111
singletons, 106
software, concurrency in
functional programming languages, 2–3
languages as contracts, 3
procedural programming languages, 2
spawning threads (listing 2.1), 10
start method, Thread class, 10
starting
starving threads, 19
static analysis tools, 167–168
Findbugs, 169
stopSelf method, 101
stopService method, 101
stubs, 115
support library annotations, 178–179
switched messages, 83
mutexes
definition, 12
reentrant monitors, 15
this keyword, 13
notify and notifyAll methods, 22–23
synchronized keyword, 12, 14–15
target field (Messages), 82
task scheduling. See scheduling tasks
terminating processes, 33
this keyword, 13
thread safety in task scheduling, 128
asynchronous execution with closures, 41–45
Binder threads, 125
executors
optimum number of threads, 25–26
initializing as loopers, 84
interruptions, 51
Runnable interface, 11
sharing data, safe publication, 23–25
synchronization, 11
notify and notifyAll methods, 22–23
reentrant monitors, 15
this keyword, 13
@ThreadSafe annotation, 178
timed-wait, 86
Timer class, 130
TimerTask class, 130
tools
annotations, 177
support library annotations, 178–179
type-safe templates, 45
@UIThread annotation, 178
unbindService method, 104, 106–107
unmarshaling, 99
unmodifiable method, 54
Updike, John, 41
varargs, 47
von Neumann, John, 1
web applications
Android applications versus, 35
when field (Messages), 82
Whyte, William H., 127
@WorkerThread annotation, 178
writeToParcel method, 116
Yegge, Steve, 106
3.149.244.67