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.setJ3DThreadPrioritymethod. The priority must fall between Thread.MAX_PRIORITYand 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 runmethod 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 313
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
CHAPTER 18 Java 3D system architecture 18.1 Introduction 18.2 Threads running a Java 3D application 18.3 MasterControl 18.4 BehaviorScheduler 18.5 InputDeviceScheduler 18.6 Renderer 18.7 StructureUpdateThread 18.8 TimerThread 18.9 SceneGraphObject 18.10 Node types 18.11 Exception Strings 18.12 J3D DLL 18.13 Summary By now I hope you are curious to know how Java 3D achieves what it does. In this chapter we gallop through some of the implementation details behind the Java 3D API gaining insight into getting the most from Java 3D and maximizing the performance of your applications. This chapter gives you some clues for implementing your own 3D graphics API in Java. Sun s Java 3D internal implementation details are all subject to change at any time. The version described here is Java 3D 1.2 running on the Win32 platform. 18.1 Introduction The implementation of the Java 3D API has undergone considerable revision between the 1.1 and 1.2 versions of the API. About 70 percent of the Java code was rewritten between these two versions! The Java 3D 1.1 architecture was fairly simplistic and could be considered a proof-of-concept implementation of the API. Version 1.2 moved to a message-based architecture and took tighter control of the various worker threads created by the API implementation. The collision detection thread was removed in 1.2, and collision detection is carried out by the new TimerThreadfunctionality. By explicitly activating the threads in the system, the 1.2 API has removed the free-running threads (behaviors and collision detection) that caused 100 percent CPU utilization in Java 3D 1.1. 312
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost Java Web Hosting services
JAR file extension options: http://java.sun.com/docs/books/tutorial/jar/index.html 17.2.5 Applets and security Security is a complex topic for applets. When SwingTestis running as an applet, it is subject to the Java sandbox principle. The applet can only read and write files from its own codebase (the URL that contains the applet). Indeed, some care must be taken while programming to ensure that applet-safe APIs are used to access files. In general, you will need to work exclusively with URL objects, as direct access using files does not always work, even when using the applet s codebase. When you run the SwingTestexample you will notice the following exceptions: Failed to save image: java.security.AccessControlException: access denied (java.io.FilePermission image.jpg write) java.security.AccessControlException: access denied (java.lang.RuntimePermission exitVM) The first exception occurs because the applet cannot write the captured image onto the local file system, while the second exception occurs because applets cannot call System.exitto exit the JVM, but are rather under the control of the Java 2 plug-in. Access permissions can be configured using the Java 2 security policy descriptors. A full discussion of Java 2 security is beyond the scope of this book. For more details refer to http://java.sun.com/j2se/1.3/docs/guide/security/ 17.3 Conclusions Installation of Java 2 client-side applications, particularly those requiring other extensions (such as Java 3D applications) is still undergoing changes and improvements. This is a bit of a mixed blessing since some of this work has been going on for about two years. However, the Java WebStart initiative demonstrates that Sun is taking the installation issue seriously. 311
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services
Figure 17.6 After installation the Java 2 plug-in icon will be available in the Windows Control Panel 17.2.4 Automatic Java 3D installation At the time of this writing it was not possible to confirm that Java 3D could be automatically installed by the Java 2 plug-in. Sun claims that this will work, but I experienced a number of problems running on Windows 98, which prevented me from verifying this. It should be possible to create a Java 3D applet that would install the Java 2 SDK, then install Java 3D and the Java 3D applet or application into the Java 2 extension directory and finally run the applet. There are a number of useful articles on Sun s web sites covering the Java 2 extension mechanism: Tutorial on the Java 2 extensions mechanism: http://java.sun.com/docs/books/tutorial/ext/index.html Java 2 SDK extensions documentation: http://java.sun.com/products/jdk/1.2/docs/guide/extensions/ 310
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services
Figure 17.4 If the end user requires a newer JRE the Java plug-in installation will be activated Figure 17.5 The end user is prompted to select a download location and begin the download and installation process 309
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services
http://java.sun.com/products/plugin/1.3/converter.html After you have installed the plug-in, you can invoke the HTML converter application and supply your original HTML file. The output from the conversion process will produce a file similar to the following:
–> 17.2.3 The end-user experience When a user with a virgin machine hits your web page, the following sequence of steps will occur: 1. User prompted to install the correct version of the Java plug-in (figure 17.4). 2. User accepts and the plug-in installation process begins (figure 17.5). 3. Plug-in is installed and can be configured through the Windows Control Panel (figure 17.6). 308
Note: If you are looking for good and high quality web space to host and run your application check Lunarwebhost JSP Web Hosting services