Threads I: Introduction

Tom Kelliher, CS 245

Oct. 10, 2008

Administrivia

Announcements

Deliverables due Wednesday.

Assignment

Complete the lab.

From Last Time

Class design.

Outline

  1. Introduction.

  2. Lab.

Coming Up

Threads II: Synchronization.

Introduction

  1. What is a thread?

  2. Why threads?

  3. How do I make a thread?
    class Foo extends applet
    {
       Bar b = new Bar();
    
       public void init()
       {
          ...
          b.start();  // Get the thread going.
          ...
       }
    }
    
    class Bar extends Thread
    {
       ...
    
       public void run()
       {
          // This is where the thread "lives."
       }
    
    Other thread methods:
    1. sleep()
    2. start()
    3. stop() -- deprecated.

Lab



Thomas P. Kelliher 2008-10-08
Tom Kelliher