Mobile Computing Dr. Mohsin Ali Memon.

Slides:



Advertisements
Similar presentations
Chap 4 Multithreaded Programming. Thread A thread is a basic unit of CPU utilization It comprises a thread ID, a program counter, a register set and a.
Advertisements

Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Intro to Threading CS221 – 4/20/09. What we’ll cover today Finish the DOTS program Introduction to threads and multi-threading.
1Threads What are they? Why are they important? How are they implemented in OSes? How to use threads? (in Java)
Threads - Definition - Advantages using Threads - User and Kernel Threads - Multithreading Models - Java and Solaris Threads - Examples - Definition -
1 School of Computing Science Simon Fraser University CMPT 300: Operating Systems I Ch 4: Threads Dr. Mohamed Hefeeda.
CS Distributed Computing Systems Chin-Chih Chang, An Introduction to Threads.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
1 Advanced Computer Programming Concurrency Multithreaded Programs Copyright © Texas Education Agency, 2013.
9/13/20151 Threads ICS 240: Operating Systems –William Albritton Information and Computer Sciences Department at Leeward Community College –Original slides.
Advanced Operating Systems CIS 720 Lecture 1. Instructor Dr. Gurdip Singh – 234 Nichols Hall –
Silberschatz, Galvin and Gagne ©2011Operating System Concepts Essentials – 8 th Edition Chapter 4: Threads.
Networking: Part 2 (Accessing the Internet). The UI Thread When an application is launched, the system creates a “main” UI thread responsible for handling.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 6.
Threads in Java. History  Process is a program in execution  Has stack/heap memory  Has a program counter  Multiuser operating systems since the sixties.
Practical OOP using Java Basis Faqueer Tanvir Ahmed, 08 Jan 2012.
1 Web Based Programming Section 8 James King 12 August 2003.
OPERATING SYSTEM SUPPORT DISTRIBUTED SYSTEMS CHAPTER 6 Lawrence Heyman July 8, 2002.
Concurrent Programming and Threads Threads Blocking a User Interface.
CS378 - Mobile Computing Responsiveness. An App Idea From Nifty Assignments Draw a picture use randomness Pick an equation at random Operators in the.
CSC Multiprocessor Programming, Spring, 2011 Chapter 9 – GUI Applications Dr. Dale E. Parson, week 11.
Threads. Readings r Silberschatz et al : Chapter 4.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts – 9 th Edition Chapter 4: Threads.
Field Trip #30 A Memory Game By Keith Lynn. View A View is the basic building block of an app Some Views hold other views An example of this is GridLayout.
Concurrent Programming in Java Based on Notes by J. Johns (based on Java in a Nutshell, Learning Java) Also Java Tutorial, Concurrent Programming in Java.
CHAPTER 6 Threads, Handlers, and Programmatic Movement.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Threads by Dr. Amin Danial Asham. References Operating System Concepts ABRAHAM SILBERSCHATZ, PETER BAER GALVIN, and GREG GAGNE.
Silberschatz, Galvin and Gagne ©2009Operating System Concepts – 8 th Edition Chapter 4: Threads.
Multithreading Chapter 6. Objectives Understand the benefits of multithreading on Android Understand multi-threading fundamentals Know the Thread class.
Concepts of Multithreading CS 378 – Mobile Computing for iOS Dr. William C. Bulko.
Introduction to Operating Systems Concepts
Chapter 4: Threads Modified by Dr. Neerja Mhaskar for CS 3SH3.
Introduction to threads
A brief intro to: Parallelism, Threads, and Concurrency
Chapter 4: Threads.
Asynchronous Task (AsyncTask) in Android
Advanced Operating Systems CIS 720
Introduction to Event-Driven Programming
PA1 Discussion.
CSC Multiprocessor Programming, Spring, 2012
CS240: Advanced Programming Concepts
Operating System (013022) Dr. H. Iwidat
Chapter 4: Multithreaded Programming
Lecture 21 Concurrency Introduction
Lecture 6: Process, Thread, Task
Lecture 28 Concurrent, Responsive GUIs
Threads & multithreading
Operating System Concepts
Chapter 4 Application Software
Chapter 4 Multithreading programming
Chapter 4: Threads.
Android Programming Lecture 8
Chapter 4: Threads.
Android App Developing with communication included
CS371m - Mobile Computing Responsiveness.
Android Topics UI Thread and Limited processing resources
CS323 Android Topics Network Basics for an Android App
Threads and Concurrency
Threads Chapter 4.
Android Topics Asynchronous Callsbacks
CHAPTER 4:THreads Bashair Al-harthi OPERATING SYSTEM
Multithreaded Programming
Android Topics Threads and the MessageQueue
Chapter 4: Threads.
Lecture 6: Process, Thread, Task
Chapter 4: Threads.
Ch 3.
Android Threads Dimitar Ivanov Mobile Applications with Android
Presentation transcript:

Mobile Computing Dr. Mohsin Ali Memon

Threads • Basic approach - Make a task list with Executors.newFixedThreadPool - Add tasks to list with taskList.execute(someRunnable) • Three variations on the theme - Separate classes that implement Runnable - Main Activity implements Runnable - Inner classes that implement Runnable - Race conditions and synchronization • Related topics - Helpful Thread-related methods

Motivation for Concurrent Programming • Pros - Advantages even on single-processor systems • Efficiency - Downloading image files • Convenience - A clock icon • Responsiveness - If you block the main thread, event handlers will not respond - Some devices have multiple cpus or cores • Find out via Runtime.getRuntime().availableProcessors() • Cons - Significantly harder to debug and maintain than single- threaded apps

Steps for Concurrent Programming

Steps for Concurrent Programming cont’d

Approach One: Separate Classes that Implement Runnable

Separate Runnable Class: Template Code This code should not update the UI. If you need to update UI, use AsyncTask class.

Thread Mechanism One: Example

Thread Mechanism One: Example con’d

Helper Class

Thread Mechanism One: Example Result

Pros and Cons of Approach

Approach Two: Main App Implements Runnable

Main App Implements Runnable: Template Code

Thread Mechanism Two: Example

Thread Mechanism Two: Results

Pros and Cons of Approach

Approach Three: Inner Class that Implements Runnable

Inner Class implements Runnable: Template code

Thread Mechanism Three: Example

Thread Mechanism Three: Example cont’d

Thread Mechanism Three: Example Result

Pros and cons of approach

Summary

Race Condition

Race Conditions: Example

Race Conditions: Example cont’d

Race Conditions: Result

Race Conditions: Solution

Race Conditions: Solution

Helpful –Thread related Methods

Methods in ExecutorService Class

Threads Cannot Update UI

Updating UI All at Once

Displaying a network image

BitmapUtils: Getting a Bitmap

Making a View for an Image

BitmapUtils:Getting a view for image

Example: Unthreaded Image Viewer

Activity

Results

Updating UI with View.post

Example: Multithreaded Image Viewer

Main Activity

Main Activity Button Handler

Main Activity: Runnable Inner Class (For Background)

Main Activity: Runnable Inner Class (For UI Thread)

Results

Downloading Images via AsyncTask