< Zurück | Inhalt | Weiter >

18.2 Threads running a Java 3D application

As you can see from tables 18.1 through 18.3, a typical Java 3D application contains many threads, some concerned with system behavior, some running the GUI event processing, and some (13) controlling the Java 3D runtime environment. The two ThreadGroups, “main” and “Java 3D,” are subgroups of the top−level “system” ThreadGroup.


The Java 3D threads have the default thread priority of 5, although this can be controlled using the VirtualUniverse.setJ3DThreadPriority method. The priority must fall between Thread.MAX_PRIORITY and Thread.MIN_PRIORITY. The default is Thread.NORM_PRIORITY. The priority of the parent ThreadGroup (Java 3D) cannot be exceeded. Note that unlike nondaemon threads, daemon threads do not have to exit their Runnable’s run method for the JVM to exit.


Table 18.1 Thread Group: System


Name

Priority

Daemon

Reference Handler

10

Yes

Finalizer

8

Yes

Signal Dispatcher

10

Yes


Table 18.2 Thread Group: Main


Name

Priority

Daemon

Main

5

No

AWT−EventQueue−0

6

No

SunToolkit.PostEventQueue−0

5

No

AWT−Windows

5

No

Image Fetcher 1

8

No

Image Fetcher 0

8

No


Table 18.3 Thread Group: Java3D


Name

Priority

Daemon

J3D−MasterControl

5

No

J3D−RenderingAttributesStructureUpdateThread

5

No

J3D−TimerThread

5

No

J3D−BehaviorStructureUpdateThread−1

5

No

J3D−GeometryStructureUpdateThread−1

5

No

J3D−SoundStructureUpdateThread−1

5

No

J3D−RenderingEnvironmentStructureUpdateThread−1

5

No

J3D−TransformStructureUpdateThread−1

5

No

J3D−BehaviorScheduler−1

5

No

J3D−RenderStructureUpdateThread−1

5

No

J3D−SoundSchedulerUpdateThread−1

5

No

J3D−InputDeviceScheduler−1

5

No

J3D−Renderer−1

5

No


The Java 3D implementation is heavily multithreaded. Typically each thread controls access to a particular data structure. The threads use the MasterControl thread to periodically synchronize and exchange notifications and messages across threads. Each thread maintains a subclass of the J3dStructure member, which contains the messages to be processed by the thread. The J3dStructure.processMessages abstract method is implemented by each subclass to examine the message queue and process messages as appropriate.


Once a message is posted to a thread by the MasterControl thread, the receiving thread is marked as having work to do and scheduled for activation. See the discussion of the MasterControl class for details of the message dispatch and processing mechanism.


Most threads are associated with an instance of a VirtualUniverse (threads with the −1 suffix), while the MasterControl, RenderingAttributesStructureUpdateThread, and TimerThread are systemwide and maintain data structures that apply across all VirtualUniverse instances.


The multithreaded nature of Java 3D allows it to leverage multiple CPUs if available; however, it does make synchronizing certain operations difficult or impossible.


 

18.2.1 Native Windows threads running a Java 3D application