Lecture 10A
MoreAboutThreads
Thread Review
Multiprocessing
Thread Subclass
Using Threads
- No interaction
- Task splitting
- Exclusive Steps
- Communicating

Thread Problems
Scheduling/Priority

Lectures

1A: Introduction
1B: Java Intro
2A: BuildingBlocks
2B: Objects
3A: More Objects
3B: Exceptions
       & Threads
4A: Waves
4B: Nuclear &
       Particle
5A: AWT
5B: More AWT
      & Graphics
6A:Detectors &
      Simulation
6B: LHC/Atlas &
     RandomSims    
7A: Swing
7B: Java2D
8A: Java Apps
8B: Dialogs &
    MoreClasses
9A: Java I/O
9B: Utilities,
        Unicode
10A: More
    Threading
10B: File
    Handling
11A: Array,Print,
    Images
11B: SimplePhysics
    Simulation
12A: Tips &
    Techniques
12B: More Tips &
    Techniques
13A: Satellite
    
Simulations
13B: Intro to Java
    Networking
14A: Java Servers
14B: HTTP Server
15A: ServerClient
15B: ServerClient
   Expt.Simulation
16A: Course
          Review
16B: ExerciseTest
        Discussion

    Contacts
    Description
    Exercises
    Index
    Outline
    Q&A
    Resources
    StudentInfoForm
    Student Pages
    What's New

 

Home : Lectures : Lecture 10A : Thread Review
Thread Review

Before preceeding with threads we should first look again at what the basics of how they work.

We can use a simple crude model of a processor to illustrate the concepts involved.

When a program is run, the registers contain the current state of execution, which includes a pointer to the memory address of the next instruction.

When the program flow jumps to another location, e.g. when a method call occurs, the current register values are saved on a stack and a new next-instruction-address, as well as other register values are loaded.

When the flow returns to the original location, the old register values are popped off the stack and loaded back into the registers.

Note: to allow for many layers of method calls, the stack should be as large as possible.

Multi-threading involves maintaining more than one stack and switching between them.

This diagram illustrates multi-threading:

A separate stack in this case is maintained for each thread.

Suppose Thread 1 represents the initial process flow. At some point, determined by the multi-processing architecture, the processing is stopped, and the current registers are saved on the Thread 1 stack.

The top of the Thread 2 stack replaces the registers and then the processing continues.

At some point in time, the processing stops again and the current registers are saved on the Thread 2 stack. The Thread 3 stack values are popped off and fill the registers and processing continues.

This switching in and out of the different thread stacks proceeds in this manner until the program finishes. Individual threads may finish during the processing and new ones created.

This illustrates how multiple threads are created within a single process.

 

Home Lectures Resources Index Contacts Students


Physics Simulations with JavaTM
KTH, Kurskod: 5A1418
Curator: Clark S. Lindsey