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 Scheduling & Priority
Thread Scheduling & Priority

The determination of when threads run is left up to the JVM implementation to allow maximum flexiblity for the various applications of Java.

Threads are assigned priorties between 1 (lowest) to 10(highest).

A thread can set its own thread up or down in priority.

Three standard priority values are defined:

  MIN_PRIORITY
  NORM_PRIORITY
  MAX_PRIORITY

For example,

...
Thread threadX=new Thread(this);
threadX.setPriority(Thread.NORM_PRIORITY + 1);
threadX.start();
..

For threads at the same priority, once one of them starts running, it continues until one of the following happens:

  • Sleeps - sleep() or wait() called
  • Waits for a lock in a synchronized method
  • Blocks on I/O such as a read()
  • Yields control with a yield() call
  • Terminates - e.g. returns from run()

Preemptive or time-slicing context switching, available on some JVMs, also will move threads of same priority in and out of control.

 

 

Home Lectures Resources Index Contacts Students


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