![]() |
Help: Thread Priority and Scheduling
Help is available for each task, or you can go straight to the solution source code.
Use the appletViewer to run the applet. Task 2Modify the run method of PingThread to have it sleep for a random amount between pings. Examine runtime behavior by running the applet several times.Add a call to sleep after ping in PingThread's run method. Use Math.random to generate a random number between 0 and 1, then mulitiply by an integer and cast to an int to get an integer range of random numbers. Be sure to catch InterruptedException when making the sleep call. Task 3Remove the sleep call, and instead have each PingThread yield after each ping. Examine runtime behavior by running the applet a few times.Remove the call to sleep. Add a call to yield after ping in PingThread's run method. Task 4Modify the priority of one thread to be higher than the others. Examine its runtime behavior with and without a random sleep in it's run method. Also examine with a yield in the run method.Add a temorary variable to hold the chosen PingThread after creation, change the priority to one plus normal priority. Add a sleep call in its run method as in the second task above. |
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |