Stopping a Thread

Chapter 6 - Thread Prioritization

Java Thread Programming
Paul Hyde
  Copyright 1999 Sams Publishing

System Thread Priorities
Back in Chapter 3, Creating and Starting a Thread, Table 3.1 listed the threads that are normally started by the VM for applications with a graphical user interface. Tables 6.1, 6.2 , and 6.3 show the priorities that are assigned to each of these system threads for each major release of Suns JDK.
Table 6.1  System Thread PrioritiesJDK 1.2
Priority
Thread Name
5
main
8
Finalizer
10
Reference Handler
5
Signal dispatcher
5
AWT-Windows
6
AWT-EventQueue-0
5
SunToolkit.PostEventQueue-0
4
Screen Updater
Table 6.2  System Thread PrioritiesJDK 1.1
Priority
Thread Name
5
main
1
Finalizer thread
5
AWT-Windows
5
AWT-EventQueue-0
4
Screen Updater
Table 6.3  System Thread PrioritiesJDK 1.0
Priority
Thread Name
5
main
1
Finalizer thread
5
AWT-Win32
5
AWT-Callback-Win32
4
Screen Updater
Chapter 3 provides descriptions of what these threads are used for and provides a cross-reference between the releases. The main thread is created by the VM and enters the main() method of applications. It runs at a middle-of-the-road priority of 5 . The asynchronous garbage collection process uses the Finalizer thread. A notable change in JDK 1.2 is that the priority of the Finalizer thread was increased from 1 to 8 to help ensure that the garbage collector gets more of a chance to run and free up memory.
The AWT-EventQueue-0 thread is the event-handling thread. This thread invokes event-handling methods in response to GUI interactions with the user. In JDK 1.2, its priority is 6 , just slighter higher than the priority of 5 that it had in JDK 1.1 and 1.0.
When assigning priorities to your threads, you should consider the relative priorities of the system threads to be sure your threads dont overwhelm their operations. By default, when a new Thread is constructed, it runs at the same priority as the thread that constructed it. Most new threads are constructed directly or indirectly by the main thread and will therefore run at a priority of 5 . This works well under many scenarios, but there are times when you will want to raise or lower a threads priority.

Toc


Java Thread Programming
Java Thread Programming
ISBN: 0672315858
EAN: 2147483647
Year: 2005
Pages: 149
Authors: Paul Hyde

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net