J2EEOnline
GofPatterns OOPortal
prev next prev next
  Course navigation
 
Lesson 1
Introducing multitasking
   
Multitasking is a marvelous topic that will be covered in detail in this module.
With multitasking, you can make more than one event occur at the same time in your program. While this is of course possible in other languages, doing so in C, for example, is much more difficult than in Java.
Java builds multitasking considerations directly into its language keywords, and Java provides classes and interfaces that make multitasking a breeze. In addition, Java provides a platform-independent way to implement multitasking.
In this module, you will learn the basic concepts of multitasking, including:
  1. Threads
  2. A metaphor for multiple threads
  3. Problems involving multiple threads

You will learn about the Thread class, including
  1. How to create and start a thread
  2. The thread life cycle
  3. How a thread's priority determines when it runs
  4. How to implement the run() method for a thread

We will dive into keywords built into the Java language to help manage threads--the most important one being synchronized.
We will explore these topics mostly through the use of a program called TownHall. This program simulates a group of noisy citizens at a town hall meeting. Each citizen will be implemented as a separate thread of control, spouting off opinions whenever possible. Through synchronization, we will create an emcee for this town hall event to ensure each citizen's comments are heard without being trampled on.
The basic example of a town hall application discussed in this module's lesson comes from Chapter 11 in Java Essentials for C and C++ Programmers.
  Course navigation