878 Multithreading Chapter 15 (Email web hosting) In Thinking About Objects
878 Multithreading Chapter 15 In Thinking About Objects Section 10.22, we encountered a problem with the collaboration diagram of Fig. 10.26 the waitingPassenger (the Person waiting to ride the Elevator) always enters the Elevator before the ridingPassenger (the Person riding the Elevator) exits. Proper use of multithreading in Java avoids this problem by guaranteeing that the waitingPassenger must wait for the ridingPassenger to exit the Elevator as would happen in real life. In our collaboration diagrams, objects pass messages to other objects by calling methods of those other objects a sending object may proceed only after a method returns. Java refers to such a message pass as a synchronous call. However, the synchronous call is not synchronized, because several objects may access the method at the same time the synchronous call cannot guarantee exclusivity to one object. This poses a problem when we model our elevator simulation, because according to Fig. 10.26, the waitingPassenger and the ridingPassenger may occupy the Elevator at the same time, which violates the capacity-of-one requirement specified in the problem statement. In this section, we use a synchronizedmethod to guarantee that only one Person may occupy the Elevator at a time. Threads, Active Classes and Synchronized Methods Java uses threads flows of program control independent of other flows to represent independent, concurrent activities. The UML provides the notion of an active class to represent a thread. Classes Elevator and Person are active classes (threads), because their objects must be able to operate concurrently and independently of one another and of other objects in the system. For example, the Elevator must be able to move between Floors while a Personis walking on a Floor. Figure 15.8 updates the collaboration diagram of Fig. 10.26 to support active classes, which are denoted by a thick black border in the diagram. To ensure that Persons enter and exit the Elevator in the proper order, we require a specific order in which to send messages the Elevator must send message 3.3.1 (ridingPassenger exits) before sending message 3.2.1.1 (waiting- Passenger enters the Elevator). The UML provides a notation to allow synchronization in collaboration diagrams if we have two messages A and B, the notation B/A indicates that message A must wait for B to complete before message A occurs. For example, the 3.3.1/3.2.1.1 notation before the enterElevator message indicates that waitingPassengermust wait for ridingPassengerto exit the Elevator (message 3.3.1) before entering (message 3.2.1.1). Software Engineering Observation 15.5 Messages in collaboration diagrams must complete in order (e.g., message 3.1 must complete before issuing message 3.2). However, messages between active classes may specify different ordering as necessary to guarantee synchronization between certain messages. A Person must synchronize with the Elevator when traveling to guarantee that only one Person occupies the Elevator at a time. In Fig. 15.8, we include the ride message (3.2.1.2) to represent the Person riding the Elevatorto the other Floor. The {concurrent} keyword placed after the ride message indicates that method rideis synchronized when we implement our design in Java. The Elevator contains method ride for the Person to allow the synchronization.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.