![]() |
Help: Using Synchronized Methods
Help is available for each task, or you can go straight to the solution source code.
Add the synchronized keyword to the push, pop and toString methods. Task 2Create a new subclass of Thread, StackStuffer, to repeatedly push ten strings on the stack, then pop five of them off. Add a call to SyncTest.stackDone after that.The structure of this class is similar to the first Clock given in the previous Magercise. It's constructor takes an Object to push on to the stack, and a SimpleStack to use. Its run method has two loops, the first pushes the given object ten times, the second calls pop five times. Then add the call to SyncTest.stackDone, use the Object pushed as the argument to the method. Task 3In the start method of SynchTest, create a SimpleStack and two new instances of StackStuffer with strings to push onto the stack, then start them off.Create two StackStuffer variables and initialize them with two new instances. Use the string "joe" for the Object argument of the first, and "bob" for the second. Call the start method on the first StackStuffer created, then the second. |
Copyright © 1996-1997 MageLang Institute. All Rights Reserved. |