V0.01 © 2009 Research In Motion Limited Introduction to Java Application Development for the BlackBerry Smartphone Trainer name Date.

Slides:



Advertisements
Similar presentations
1 Multithreaded Programming in Java. 2 Agenda Introduction Thread Applications Defining Threads Java Threads and States Examples.
Advertisements

How to Build Multi- threaded Applications in.NET Mazen S. Alzogbi Technology Specialist Microsoft Corporation.
1 Chapter 5 Threads 2 Contents  Overview  Benefits  User and Kernel Threads  Multithreading Models  Solaris 2 Threads  Java Threads.
V0.1 Inclusive and Accessible Application Design June 21, 2012.
Java How to Program, 9/e CET 3640 Professor: Dr. José M. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Intro to Threading CS221 – 4/20/09. What we’ll cover today Finish the DOTS program Introduction to threads and multi-threading.
Multithreading The objectives of this chapter are:
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L19 (Chapter 24) Multithreading.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
Concurrency…leading up to writing a web crawler. Web crawlers.
CS220 Software Development Lecture: Multi-threading A. O’Riordan, 2009.
V0.01 © 2009 Research In Motion Limited Introduction to Java Application Development for the BlackBerry Smartphone Trainer name Date.
V0.01 © 2009 Research In Motion Limited Introduction to Java Application Development for the BlackBerry Smartphone Trainer name Date.
V0.01 © 2009 Research In Motion Limited Introduction to Java Application Development for the BlackBerry Smartphone Trainer name Date.
V0.01 © 2009 Research In Motion Limited Understanding Java APIs for Mobile Devices Trainer name Date.
Cosc 4755 Phone programming: GUI Concepts & Threads.
A. Frank - P. Weisberg Operating Systems Introduction to Tasks/Threads.
1 Threads Chapter 4 Reading: 4.1,4.4, Process Characteristics l Unit of resource ownership - process is allocated: n a virtual address space to.
V0.01 © 2009 Research In Motion Limited Push technology for Java applications Trainer name Date.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L20 (Chapter 24) Multithreading.
Java How to Program, 9/e CET 3640 Professor: Dr. Reyes Álamo © Copyright by Pearson Education, Inc. All Rights Reserved.
Multithreading.
V0.1 BlackBerry HTML5/WebWorks Applications for the BlackBerry ® PlayBook™ Tablet BlackBerry Academic Program Module 1 - Overview.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
Java Programming: Advanced Topics
V0.1 BlackBerry HTML5/WebWorks Applications for the BlackBerry ® PlayBook™ Tablet BlackBerry Academic Program Module 5 - Writing HTML5/WebWorks API Extensions.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
PROG Mobile Java Application Development PROG Mobile Java Application Development BlackBerry App Lifecycle Java ME API.
Multi-Threaded Application CSNB534 Asma Shakil. Overview Software applications employ a strategy called multi- threaded programming to split tasks into.
Quick overview of threads in Java Babak Esfandiari (extracted from Qusay Mahmoud’s slides)
Dr. R R DOCSIT, Dr BAMU. Basic Java : Multi Threading 2 Objectives of This Session State what is Multithreading. Describe the life cycle of Thread.
111 © 2002, Cisco Systems, Inc. All rights reserved.
1 Web Based Programming Section 8 James King 12 August 2003.
A Guide to Advanced Java Faculty:Nguyen Ngoc Tu. Concurrent programming in Java How to make all things run-able?
Multithreading in Java Sameer Singh Chauhan Lecturer, I. T. Dept., SVIT, Vasad.
© 2009 Research In Motion Limited Advanced Java Application Development for the BlackBerry Smartphone Trainer name Date.
Introduction to Threads Session 01 Java Simplified / Session 14 / 2 of 28 Objectives Define a thread Define multithreading List benefits of multithreading.
Multithreading Chapter Introduction Consider ability of _____________ to multitask –Breathing, heartbeat, chew gum, walk … In many situations we.
Multithreading Chapter Introduction Consider ability of human body to ___________ –Breathing, heartbeat, chew gum, walk … In many situations we.
Java Thread and Memory Model
15.1 Threads and Multi- threading Understanding threads and multi-threading In general, modern computers perform one task at a time It is often.
Concurrent Computing CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
Multi-Threading in Java
© Janice Regan, CMPT 300, May CMPT 300 Introduction to Operating Systems Operating Systems Processes and Threads.
Chapter11 Concurrent. 集美大学 计算机工程学院 Java 程序设计 年 第二版 Concurrent ●Computer users take it for granted that their systems can do more than one thing.
Internet Computing Module II. Threads – Multithreaded programs, thread Priorities and Thread Synchronization.
Multithreading. Multitasking The multitasking is the ability of single processor to perform more than one operation at the same time Once systems allowed.
Type presentation name here in slide master © 2007 SDL. Company Confidential. Forward-looking information is based upon multiple assumptions and uncertainties.
1 Threads in Java Jingdi Wang. 2 Introduction A thread is a single sequence of execution within a program Multithreading involves multiple threads of.
Concurrency in Java MD. ANISUR RAHMAN. slide 2 Concurrency  Multiprogramming  Single processor runs several programs at the same time  Each program.
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.
Threads, SMP, and Microkernels Chapter 4. Processes and Threads Operating systems use processes for two purposes - Resource allocation and resource ownership.
Multithreading The objectives of this chapter are:
Multithreading / Concurrency
Multi Threading.
Multithreaded Programming in Java
Lecture 28 Concurrent, Responsive GUIs
Multithreading Chapter 23.
Multithreading.
Multithreading.
Multithreaded Programming
Threads Chapter 4.
NETWORK PROGRAMMING CNET 441
Threads and Multithreading
Multithreading The objectives of this chapter are:
CMSC 202 Threads.
Java Chapter 3 (Estifanos Tilahun Mihret--Tech with Estif)
Presentation transcript:

v0.01 © 2009 Research In Motion Limited Introduction to Java Application Development for the BlackBerry Smartphone Trainer name Date

© 2009 Research In Motion Limited Revision history Document versionDateUpdated byDescription of revision.01Brian WhiteInitial content creation

Agenda In this course, you will cover the following topics: –Introduction to Java® application development for mobile devices –Understanding Java APIs for mobile devices –Developing a user interface for mobile devices –Push technology for Java applications –Introduction to threading and background processing –Network communication for mobile devices –Testing and debugging an application API application programming Interface

Introduction to threading and background processing Objectives: –Describe multithreaded applications –Describe the Main Event thread –Describe background applications –Describe how to create and use threads –Describe the dangers of multithreaded applications

© 2009 Research In Motion Limited Multithreaded applications

–Traditionally, applications run in a single thread of execution: each task the application must perform during the course of its execution happens in a sequence, one task at a time. –Multithreaded applications can create multiple threads of execution (known as spawning a thread) that perform many tasks concurrently.

Multithreaded applications –On the left is an application performing three tasks in a single thread of execution. Each task is in succession and cannot start the next task before finishing the previous one. –On the right is an application performing the same tasks with multiple threads of execution. The application places each task in its own thread of execution simultaneously and returns the data when the task is complete while the main thread of execution (the main application) continues to operate.

Multithreaded applications Benefits: –Improved application responsiveness –Efficient multiprocessor use –Efficient system resource usage

Main Event thread

–Is the thread of execution in every Java® ME application developed for the BlackBerry® smartphone –Is the center point from which all other threads of execution are launched in the application –The Main Event thread is designated by calling the Application.enterEventDispatcher() method.

Main Event thread Example: public class SimpleApp extends UiApplication { public static void main(String[] args) { MyApp app = new MyApp(); app.enterEventDispatcher() } –Class inherited from UiApplication: Any GUI application must be inherited from the UiApplication class which itself is inherited from the Application class. Part of this inheritance is the inclusion of the enterEventDispatcher() method. –Use of enterEventDispatcher() method: The enterEventDispatcher() method is called in the main() method to assign event dispatching duties to this thread. The method is called on an instance of the class instantiated in the main() method.

Main Event thread Use the Main Event thread to: –Control the overall execution of the application –Serve as the main launching and collapsing point of all threads of execution in the complete application.

Background applications

–Run in a separate process that does not interfere with the other applications and processes running on the BlackBerry smartphone –Can theoretically perform any number of tasks; a common use is to listen for data being pushed to the device –Run as self-contained programs in separate processes

Creating and using threads

–Create runnable classes –Create and start threads –Suspend threads –Prioritize threads –Stop threads

Creating and using threads Create runnable classes: –For multiple inheritance in classes, the Java APIs provide either the Thread class or the Runnable interface. –The Runnable interface is the one method used to create a runnable class. Can inherit functionality from another fully formed class. An interface provides a framework that any classes that implement it must follow. This gives the developer much more flexibility in the classes they create. –The Thread class is easier to use, but limited. Can only use interfaces to lend additional functionality.

Creating and using threads Create and start threads: –Create and instance of the class as an object. 1.Ensure the class to be used is within the scope of the current class. 2.Declare an object variable. 3.Instantiate the object. –After a threaded class is properly instantiated into an object, it is ready for execution. –To begin execution call the start() method.

Creating and using threads Suspend threads: –After a thread of execution is stopped, it cannot be restarted. Threads of execution can be suspended and resumed. There are two methods for suspending thread execution. Thread suspension—Threads can be manually suspended and resumed. Thread sleeping—Threads can be suspended for a set amount of time using the sleep() method and passing the amount of time in milliseconds to suspend the thread. Wait and notify—The wait() and notify() methods work in conjunction to suspend and wake threads that require access to a group of objects.

Creating and using threads Prioritize threads: –Prioritize threads to ensure they are executed before other threads spawned by the application. –Prioritization applies only in the context of the current application. –A useful technique for ensuring that some threads are executed before others. –Thread prioritization is accomplished using the setPriority() method of the threaded object and passing a numeric value that represents the new priority. –Thread priority works on an ascending scale.

Creating and using threads Stop threads: –Although any threaded object provides a stop() method for ending execution, this method can sometimes cause problems in applications. –A better solution is to fashion code that interrupts the execution of the thread.

Dangers of multithreaded applications

–A TooManyThreadsError exception will be returned by an application that has reached either the application or operating system maximums for thread creation. This exception should be handled during any thread creation code. Refer to the relevant J2ME and BlackBerry smartphone operating system documentation for current maximums. –Long-running threads (such as those found in background applications) should occasionally be suspended so their resources can be freed up for other threads of execution.

Dangers of multithreaded applications –All threads of execution spawned by applications that are not designed to run in the background should be ended by the time the application itself ends. –To end a thread of execution use coded methods instead of the stop() method. The stop() method can cause damage to objects associated with the thread of execution, and even though the thread may exit, other parts of the application might still use these objects.

Summary –Multithreaded applications have the ability to create multiple threads of execution that perform many tasks in a concurrent fashion. –The BlackBerry smartphone operating system supports multithreading so developers can create responsive applications that best exploit the unique features of the operating environment. –Multithreaded applications provide the following key advantages: Improved application responsiveness Efficient multiprocessor use Efficient system resource usage

Summary –A background application is one that runs in a separate process that does not interfere with the other applications and processes running on the BlackBerry smartphone. –A runnable class can be created from the Thread class or the Runnable interface. The Runnable interface is preferable because it allows a developer to further inherit from another class. –Runnable classes expose the run() method to perform the threaded work. –Thread execution can be frozen through either thread suspension or thread sleeping. –It is preferable to stop thread execution through a coded method other than explicitly calling the stop() method. –There are many risks inherent in using multithreaded applications. Be aware of these risks during the development process.

© 2009 Research In Motion Limited

Legal Disclaimer The following trademarks and/or registered trademarks of Research In Motion are referred to in this presentation: –BlackBerry® –Research In Motion® (only include if it appears in the webinar/presentation) –RIM® (only include if it appears in the webinar/presentation) The following BlackBerry products are referred to in this presentation: (include all items from the official BlackBerry products list that appear in the webinar/presentation) –BlackBerry® Internet Service –BlackBerry® Enterprise Solution –BlackBerry® Enterprise Server –BlackBerry® Pearl™ 8100 smartphone –BlackBerry® Curve™ 8300 smartphone The following third-party trademarks are referred to in this presentation: (include all third-party products that appear in the webinar/presentation) –Microsoft® Excel® –Microsoft® SQL Server® Please remove any products not mentioned in this presentation and add all mentioned products before completing this presentation. Also, remove any remaining red text. © 2009 Research In Motion Limited

Legal Disclaimer © 2009 Research In Motion Limited. All rights reserved. BlackBerry®, RIM®, Research In Motion®, SurePress™ SureType® and related trademarks, names and logos are the property of Research In Motion Limited and are registered and/or used in the U.S. and countries around the world. All other trademarks are the property of their respective owners. This documentation is provided "AS IS" and without condition, endorsement, guarantee, representation or warranty, or liability of any kind by Research In Motion Limited and its affiliated companies, all of which are expressly disclaimed to the maximum extent permitted by applicable law in your jurisdiction.

© 2009 Research In Motion Limited Revision history Document versionDateUpdated byDescription of revision