Mapping Classes To Patterns In Java & Android's Concurrency Frameworks

1y ago
23 Views
2 Downloads
935.33 KB
25 Pages
Last View : 9d ago
Last Download : 3m ago
Upload by : Gannon Casey
Transcription

Mapping Classes to Patterns in Java & Android’s Concurrency Frameworks Douglas C. Schmidt d.schmidt@vanderbilt.edu www.dre.vanderbilt.edu/ schmidt Institute for Software Integrated Systems Vanderbilt University Nashville, Tennessee, USA

Learning Objectives in this Lesson Understand the mapping of Android concurrency classes to software patterns Android/Java Mechanism Pattern Looper Thread-Specific Storage HaMeR framework & Java Executor framework Command Processor & Active Object AsyncTask framework Half-Sync/Half-Async Java LinkedBlockingQueue Monitor Object Java Streams framework Pipes & Filters 8

Elements of Android Concurrency Frameworks 9

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Message Handler Looper Handler Message Message Runnable Message Background Thread B Message Message UI Thread (main thread) 10 FutureTask Message Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Message Handler Looper Handler Message Message Runnable Message Background Thread B Message Message UI Thread (main thread) Earlier we covered classes used to write concurrent11 Android programs FutureTask Message Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Message Handler Looper Handler Message Message Runnable Message Background Thread B Message Message UI Thread (main thread) We now explore the implementation 12 of Android’s concurrency frameworks FutureTask Message Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Message Handler Looper Handler Message Message Runnable Message Background Thread B Message Message UI Thread (main thread) See upcoming section on “Android 13 Concurrency Frameworks: Patterns” FutureTask Message Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Message We cover the most important classes in the Android concurrency frameworks Handler Looper Handler Message Message Runnable Message Background Thread B Message Message UI Thread (main thread) 14 FutureTask Message Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Message Handler Some classes are used by both the HaMeR & AsyncTask concurrency frameworks Looper Handler Message Message Runnable Message Background Thread B Message Message UI Thread (main thread) 15 FutureTask Message Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Looper Run a message loop for Message a thread Handler Looper Handler Message Message Message Message Message Message UI Thread (main thread) See developer.android.com/ 16 reference/android/os/Looper.html Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Looper Run a message loop for Message a thread Handler Applies Thread-Specific Storage Handler Looper pattern to ensure only one Looper is allowed per Thread Message Message Message Message Message Message UI Thread (main thread) See www.dre.vanderbilt.edu/ 17 schmidt/PDF/TSS-pattern.pdf Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Background Thread A Message Queue are built using reusable classes Looper MessageQueue Holds the list Message Handler of messages to be dispatched by a Looper Looper Handler Message Message Message Message Message Message UI Thread (main thread) See developer.android.com/reference/ 18 android/os/MessageQueue.html Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks are built using reusable classes Looper MessageQueue Holds the list Message Handler of messages to be dispatched by a Looper Handler to enqueue /dequeue Messages concurrently & efficiently Looper Applies Monitor Object pattern Background Thread A Message Queue Message Message Message Message Message Message UI Thread (main thread) See www.dre.vanderbilt.edu/ 19 schmidt/PDF/monitor.pdf Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks are built using reusable classes Looper MessageQueue Message Contains data & type Message Handler Handler Looper information that can be sent to a Handler via a MessageQueue Background Thread A Message Queue Message Message Message Message Message Message UI Thread (main thread) See developer.android.com/reference/ 20 android/os/Message.html Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks are built using reusable classes Looper MessageQueue Message Contains data & type Messages are created via Factory Method pattern Message Handler Handler Looper information that can be sent to a Handler via a MessageQueue Background Thread A Message Queue Message Message Message Message Message Message UI Thread (main thread) See en.wikipedia.org/wiki/ 21 Factory method pattern Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks are built using reusable classes Looper Message MessageQueue Handler Message Handler Allows the sending & processing of Message & Runnable objects in the MessageQueue associated with a Thread’s Looper Handler Looper Background Thread A Message Queue Message Message Message Message Message Message UI Thread (main thread) See developer.android.com/reference/ 22 android/os/Handler.html Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks are built using reusable classes Looper Message MessageQueue Handler Message Handler Allows the sending & processing of Message & Runnable objects in the MessageQueue associated with a Thread’s Looper Handler Looper Background Thread A Message Queue Handlers support Active Object & Command Processor patterns to allow sender & receiver Threads to run concurrently Message Message Message Message Message Message UI Thread (main thread) See www.dre.vanderbilt.edu/ schmidt/ 23 PDF/{Act-Obj,CommandProcessor}.pdf Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks are built using reusable classes Looper Message MessageQueue Handler Message Handler Handler Runnable Represents a command that can be executed Looper Background Thread A Message Queue Message Message Message Message Message Message UI Thread (main thread) See developer.android.com/reference/ 24 java/lang/Runnable.html Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks are built using reusable classes Looper Message MessageQueue Handler Message Handler Handler Looper Background Thread A Message Queue Runnable Represents a command that can be executed Message Message Message Supports Command Processor pattern to pass commands from one Thread to another Message Message Message UI Thread (main thread) See www.dre.vanderbilt.edu/ 25 schmidt/CommandProcessor.pdf Runnable Background Thread B

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Message Queue are built using reusable classes Looper MessageQueue Handler Runnable Message Message Message Message Some classes are just used by the AsyncTask concurrency framework Message Message UI Thread (main thread) 26 FutureTask Message Looper Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Message Queue are built using reusable classes Looper MessageQueue Handler Runnable FutureTask Start & cancel an asynchronous computation, query to see if the computation is complete, & retrieve the result of the computation Message Message Message Message Message Message UI Thread (main thread) See developer.android.com/reference/ 27 java/util/concurrent/FutureTask.html FutureTask Message Looper Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Message Queue are built using reusable classes Looper MessageQueue Handler Runnable FutureTask Start & cancel an asynchronous computation, query to see if the computation is complete, & retrieve the result of the computation Supports the Future pattern Message Message Message Message Message Message to block client only if computation isn’t finished UI Thread (main thread) See en.wikipedia.org/wiki/ 28 Futures and promises FutureTask Message Looper Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Message Queue are built using reusable classes Looper MessageQueue Handler Runnable FutureTask Executor framework Execute submitted Runnable tasks either sequentially or in a pool of threads Message Message Message Message Message Message UI Thread (main thread) See developer.android.com/reference/ 29 java/util/concurrent/Executor.html FutureTask Message Looper Handler Executor AsyncTask

Elements of Android Concurrency Frameworks Android’s concurrency frameworks Message Queue are built using reusable classes Looper MessageQueue Handler Runnable FutureTask Executor framework Execute submitted Runnable tasks either sequentially or in a pool of threads Implements Proactor, Active Object, & Pooling patterns Message Message Message Message FutureTask Message Looper Handler Executor AsyncTask Message Message UI Thread (main thread) See en.wikipedia.org/wiki/Proactor pattern, en.wikipedia.org/wiki/ 30 Active object, & ng.pdf

End of Mapping Classes to Patterns in Java & Android’s Concurrency Frameworks 31

Android's concurrency frameworks are built using reusable classes Looper Run a message loop for a thread Applies Thread-Specific Storage pattern to ensure only one Looper is allowed per Thread Elements of Android Concurrency Frameworks Message Message Message Message Message Message Queue UI Thread (main thread) Message

Related Documents:

concept mapping has been developed to address these limitations of mind mapping. 3.2 Concept Mapping Concept mapping is often confused with mind mapping (Ahlberg, 1993, 2004; Slotte & Lonka, 1999). However, unlike mind mapping, concept mapping is more structured, and less pictorial in nature.

Argument mapping is different from mind mapping and concept mapping (Figure 1). As Davies described, while mind mapping is based on the associative connections among images and topics and concept mapping is concerned about the interrelationships among concepts, argument mapping “ is interested in the inferential basis for a claim

Mapping is one of the basic elements in Informatica code. A mapping with out business rules are know as Flat mappings. To understand the basics of Mapping in Informatica, let us create a Mapping that inserts data from source into the target. Create Mapping in Informatica. To create Mapping in Informatica, open Informatica PowerCenter Designer .

LLinear Patterns: Representing Linear Functionsinear Patterns: Representing Linear Functions 1. What patterns do you see in this train? Describe as What patterns do you see in this train? Describe as mmany patterns as you can find.any patterns as you can find. 1. Use these patterns to create the next two figures in Use these patterns to .

Mind mapping Mind mapping (or ‘‘idea’’ mapping) has been defined as ‘visual, non-linear representations of ideas and their relationships’ (Biktimirov and Nilson 2006). Mind maps comprise a network of connected and related concepts. However, in mind mapping, any idea can be connected to

Mapping Analyst for Excel includes mapping specifications and metamaps. Mapping Specifications A mapping specification is a Microsoft Excel file that includes metadata to import into the PowerCenter repository. Use a mapping specification to define sources or targets or to define a mapping by describing the

i. Definition of Utility Mapping. ii. History of Utility Mapping. iii. Objectives of Utility Survey & Mapping in Malaysia. iv. The scope of Utility Mapping in standard guidelines for underground utility mapping. v. The role of utility owner, surveyor and JUPEM in underground utility mapping. 1 UNDERSTAND THE UTILITY QUALITY LEVEL ATTRIBUTES i.

1. Transport messages Channel Patterns 3. Route the message to Routing Patterns 2. Design messages Message Patterns the proper destination 4. Transform the message Transformation Patterns to the required format 5. Produce and consume Endpoint Patterns Application messages 6. Manage and Test the St Management Patterns System