Android Concurrency & Synchronization: Part 8
Android Concurrency &
Synchronization: Part 8
Douglas C. Schmidt
d.schmidt@vanderbilt.edu
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 & Synchronization
Douglas C. Schmidt
Challenge: Ensuring One Looper per Thread
Context
? Android only allows one Looper per Thread
Looper
Looper
Message
Queue
Message
Message
Message
Message
Message
Message
Thread1
2
developer.reference/android/os/Looper.html
has more info
Android Concurrency & Synchronization
Douglas C. Schmidt
Challenge: Ensuring One Looper per Thread
Problem
? Using a central ¡°Looper registry¡±
in a multi-threaded process
could become a bottleneck
Synchronization is required
to serialize access by
multiple threads
public class Looper {
...
static final HashMap looperRegistry = new
HashMap();
...
private static void prepare() {
synchronized(Looper.class) {
Looper l = looperRegistry.
get(Thread.getId());
if (l != null)
throw new
RuntimeException("Only
one Looper may be
created per thread");
looperRegistry.put
(Thread.getId(),
new Looper());
}
3 ...
Android Concurrency & Synchronization
Douglas C. Schmidt
Challenge: Ensuring One Looper per Thread
Solution
public class Looper {
...
? Apply the Thread-Specific Storage
static final ThreadLocal
pattern to allow multiple threads
sThreadLocal = new
to use one ¡®logically global¡¯ access
ThreadLocal();
point to retrieve the one & only
...
Looper that is local to a thread
private static void prepare() {
Thread-Specific Storage doesn¡¯t incur
locking overhead on each object access
if (sThreadLocal.get()
!= null)
throw new
RuntimeException("Only
one Looper may be
created per thread");
sThreadLocal.set(new
Looper(quitAllowed));
}
...
4
developer.reference/java/lang/ThreadLocal.html
has more info
Android Concurrency & Synchronization
Douglas C. Schmidt
Thread-Specific Storage POSA2 Synchronization
Intent
? Allows multiple threads to use one ¡®logically global¡¯ access point to retrieve
an object that is local to a thread, without incurring locking overhead on
each object access
5
dre.vanderbilt.edu/~schmidt/PDF/TSS-pattern.pdf
has more info
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- deep dive into android ipc binder framework at android
- android concurrency synchronization part 8
- hybridroid analysis framework for android hybrid applications
- handling offline apability and ata sync in an
- android content providers university of texas at austin
- c basics cheat sheet 1 of 4
- parsing json
- addressing non functional requirements in mobile
Related searches
- excel sumifs contains part of text
- most important part synonym
- chapter 8 photosynthesis 8 2
- minecraft beta 1.8.0.8 download
- minecraft beta 1 8 0 8 download
- minecraft 1 8 8 download free
- log2 8 7x log2 8 3x 1
- utf 8 vs utf 8 bom
- upgrade from windows 8 to 8 1
- windows 8 0 to 8 1 upgrade
- android 8 1 0 outlook change password
- 8 8 nm to in lb