880 Multithreading Chapter 15 Method ride guarantees that
Sunday, September 16th, 2007880 Multithreading Chapter 15 Method ride guarantees that only one Personmay ride the Elevator at a time as described in Section 15.5, only one synchronizedmethod may be active on an object at once, so all other Person threads attempting to invoke ride must wait for the current thread to exit method ride. Method ride invokes static method sleep of class Thread to put the Person thread into the sleep state, which represents the Person waiting for the ride to complete. We must specify the maximum amount of time that a Person will wait for the Elevator to complete traveling however, there is no such information specified in the problem statement. We introduce a new attribute that represents this time maxTravelTime, to which we arbitrarily assign a value of 10 minutes (i.e., a Person will wait 10 minutes for the travel to complete). Attribute maxTravelTime is a safeguard in case the Elevator for whatever reason never reaches the other Floor. The Person should never have to wait this long if the Person waits 10 minutes, then the Elevator is broken, and we assume that our Person crawls out of the Elevator and exits the simulation. Software Engineering Observation 15.6 In a software-development process, the analysis phase yields a requirements document (e.g., our problem statement). As we continue the design and implementation phase, we discover additional issues that were not apparent to us at the analysis phase. As designers, we must anticipate these issues and deal with them accordingly. Software Engineering Observation 15.7 One false assumption to make is that the system requirements remain stable (i.e., they provide all information necessary to build the system) throughout the analysis and design phases. In large systems that have long implementation phases, requirements can, and often do, change to accommodate those issues that were not apparent during analysis. If our Elevator works correctly, the Elevator travels for five seconds specifically, invoking method sleep halts the Elevator s thread for five seconds to simulate the travel. When the Elevator thread awakens, it sends elevatorArrived events as described in Section 10.22. The elevatorDoor receives this event and invokes method doorOpened (message 3.3) of the ridingPassenger, as in: public void doorOpened( DoorEvent doorEvent ) { // set Person on Floor where Door opened setLocation( doorEvent.getLocation() ); // interrupt Person’s sleep method in run method and // Elevator’s ride method interrupt(); } Method doorOpened sets the ridingPassenger s Location to the Floorat which the Elevator arrived, then calls the ridingPassenger thread s interrupt method. The interrupt method terminates the sleep method invoked in method ride, method ride terminates, and the ridingPassenger leaves the Elevator, then exits the simulation. When the ridingPassenger exits the Elevator, the ridingPassenger releases the monitor on the Elevator object, which allows the waitingPassenger to invoke the ride method and obtain the monitor. Now, the waitingPassenger may invoke method ride to ride the Elevator.
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.