img
Two exiting.
Main thread exiting.
Inside the program, notice that thread group A is suspended for four seconds. As the
output confirms, this causes threads One and Two to pause, but threads Three and Four
continue running. After the four seconds, threads One and Two are resumed. Notice how
thread group A is suspended and resumed. First, the threads in group A are obtained by
calling enumerate( ) on group A. Then, each thread is suspended by iterating through the
resulting array. To resume the threads in A, the list is again traversed and each thread is
resumed. One last point: this example uses the recommended approach to suspending
and resuming threads. It does not rely upon the deprecated methods suspend( ) and
resume( ).
ThreadLocal and InheritableThreadLocal
Java defines two additional thread-related classes in java.lang:
· ThreadLocal  Used to create thread local variables. Each thread will have its own
copy of a thread local variable.
· InheritableThreadLocal  Creates thread local variables that may be inherited.
Package
Package encapsulates version data associated with a package. Package version information
is becoming more important because of the proliferation of packages and because a Java
program may need to know what version of a package is available. The methods defined by
Package are shown in Table 16-19. The following program demonstrates Package, displaying
the packages about which the program currently is aware:
// Demonstrate Package
class PkgTest {
public static void main(String args[]) {
Package pkgs[];
pkgs = Package.getPackages();
for(int i=0; i < pkgs.length; i++)
System.out.println(
pkgs[i].getName() + " " +
pkgs[i].getImplementationTitle() + " " +
pkgs[i].getImplementationVendor() + " " +
pkgs[i].getImplementationVersion()
);
}
}
Search WWH :
Custom Search
Previous Page
Java SE 6 Topic Index
Next Page
Java SE 6 Bookmarks
Home