876 Multithreading Chapter 15 is being resumed. If
876 Multithreading Chapter 15 is being resumed. If the appropriate boolean variable is false, the program calls method notifyAll (line 106) to move all waiting threads into the ready state and prepare them to resume execution. When each thread is dispatched to the processor to resume execution, the while condition at lines 139 140 in the run method fails for the resumed thread and the loop terminates. Execution of the run method then continues from line 156. For any other threads that became ready, but still are suspended, the condition at lines 139 140 remains true and the threads reenter the waiting state. The applet s stop method (lines 79 90) is provided to stop all three threads if the user leaves the Web page on which this applet resides (you can simulate this by selecting Stop from the appletviewer s Applet menu). The for loop at lines 84 85 sets each Thread reference in array threadsto null. Line 89 invokes Object method notifyAll to ensure that all waiting threads get ready to execute. When the program encounters the while loop condition at line 129 for each thread, the condition fails and the run method terminates. Thus, each thread dies. If the user returns to the Web page, the applet container calls the applet s start method to instantiate and start three new threads. Performance Tip 15.5 Stopping applet threads when leaving a Web page is a polite programming practice because it prevents your applet from using processor time (which can reduce performance) on the browser s machine when the applet is not being viewed. The threads can be restarted from the applet s start method, which is invoked by the browser when the Web page is revisited by the user. 15.11 Thread Groups Sometimes it is useful to identify various threads as belonging to a thread group; class ThreadGroup contains methods for creating and manipulating thread groups. At constructor time, the group is given a unique name via a String argument. The threads in a thread group can be manipulated as a group. It may, for example, be desirable to interrupt all the threads in a group. A thread group can be the parent thread group to a child thread group. Method calls sent to a parent thread group are also sent to all the threads in that parent s child thread groups. Class ThreadGroup provides two constructors. The constructor public ThreadGroup( String stringName ) constructs a ThreadGroup with name stringName. The constructor public ThreadGroup( ThreadGroup parentThreadGroup, String stringName ) constructs a child ThreadGroupof parentThreadGroup called stringName. Class Thread provides three constructors that enable the programmer to instantiate a Thread and associate it with a ThreadGroup. The constructor public Thread( ThreadGroup threadGroup, String stringName ) constructs a Thread that belongs to threadGroup and has the name stringName. This constructor is normally invoked for derived classes of Thread whose objects should be associated with a ThreadGroup.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.