Archive for September, 2007

Chapter 15 Multithreading 893 a reservation; stopReading to (Web design software)

Wednesday, September 26th, 2007

Chapter 15 Multithreading 893 a reservation; stopReading to be called by any reader who has finished reading a reservation; startWriting to be called by any writer who wants to make a reservation and stopWriting to be called by any writer who has finished making a reservation. 15.25 Write a program that bounces a blue ball inside an applet. The ball should be initiated with a mousePressed event. When the ball hits the edge of the applet, the ball should bounce off the edge and continue in the opposite direction. 15.26 Modify the program of Exercise 15.25 to add a new ball each time the user clicks the mouse. Provide for a minimum of 20 balls. Randomly choose the color for each new ball. 15.27 Modify the program of Exercise 15.26 to add shadows. As a ball moves, draw a solid black oval at the bottom of the applet. You may consider adding a 3-D effect by increasing or decreasing the size of each ball when a ball hits the edge of the applet. 15.28 Modify the program of Exercise 15.25 or 15.26 to bounce the balls off each other when they collide.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

892 Multithreading Chapter 15 15.22 If (Dedicated web hosting) your system

Tuesday, September 25th, 2007

892 Multithreading Chapter 15 15.22 If your system does not support timeslicing, write a Java program that demonstrates two threads using yieldto enable one another to execute. 15.23 Two problems that can occur in systems like Java, that allow threads to wait, are deadlock, in which one or more threads will wait forever for an event that cannot occur, and indefinite postponement, in which one or more threads will be delayed for some unpredictably long time. Give an example of how each of these problems can occur in a multithreaded Java program. 15.24 (Readers and Writers) This exercise asks you to develop a Java monitor to solve a famous problem in concurrency control. This problem was first discussed and solved by P. J. Courtois, F. Heymans and D. L. Parnas in their research paper, Concurrent Control with Readers and Writers, Communications of the ACM, Vol. 14, No. 10, October 1971, pp. 667 668. The interested student might also want to read C. A. R. Hoare s seminal research paper on monitors, Monitors: An Operating System Structuring Concept, Communications of the ACM, Vol. 17, No. 10, October 1974, pp. 549 557. Corrigendum, Communications of the ACM, Vol. 18, No. 2, February 1975, p. 95. [The readers and writers problem is discussed at length in Chapter 5 of the author s book: Deitel, H. M., Operating Systems, Reading, MA: Addison-Wesley, 1990.] a) With multithreading, many threads can access shared data; as we have seen, access to shared data needs to be synchronized carefully to avoid corrupting the data. b) Consider an airline-reservation system in which many clients are attempting to book seats on particular flights between particular cities. All of the information about flights and seats is stored in a common database in memory. The database consists of many entries, each representing a seat on a particular flight for a particular day between particular cities. In a typical airline-reservation scenario, the client will probe around in the database looking for the optimal flight to meet that client s needs. So a client may probe the database many times before deciding to book a particular flight. A seat that was available during this probing phase could easily be booked by someone else before the client has a chance to book it. In that case, when the client attempts to make the reservation, the client will discover that the data has changed and the flight is no longer available. c) The client probing around the database is called a reader. The client attempting to book the flight is called a writer. Clearly, any number of readers can be probing shared data at once, but each writer needs exclusive access to the shared data to prevent the data from being corrupted. d) Write a multithreaded Java program that launches multiple reader threads and multiple writer threads, each attempting to access a single reservation record. A writer thread has two possible transactions, makeReservationand cancelReservation. A reader has one possible transaction, queryReservation. e) First implement a version of your program that allows unsynchronized access to the reservation record. Show how the integrity of the database can be corrupted. Next implement a version of your program that uses Java monitor synchronization with waitand notify to enforce a disciplined protocol for readers and writers accessing the shared reservation data. In particular, your program should allow multiple readers to access the shared data simultaneously when no writer is active. But if a writer is active, then no readers should be allowed to access the shared data. f) Be careful. This problem has many subtleties. For example, what happens when there are several active readers and a writer wants to write? If we allow a steady stream of readers to arrive and share the data, they could indefinitely postpone the writer (who may become tired of waiting and take his or her business elsewhere). To solve this problem, you might decide to favor writers over readers. But here, too, there is a trap, because a steady stream of writers could then indefinitely postpone the waiting readers, and they, too, might choose to take their business elsewhere! Implement your monitor with the following methods: startReading, which is called by any reader who wants to begin accessing
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Php web hosting - Chapter 15 Multithreading 891 15.6 List each of

Tuesday, September 25th, 2007

Chapter 15 Multithreading 891 15.6 List each of the three reasons given in the text for entering the blocked state. For each of these, describe how the program will normally leave the blocked state and enter the runnable state. 15.7 Distinguish between preemptive scheduling and nonpreemptive scheduling. Which does Java use? 15.8 What is timeslicing? Give a fundamental difference in how scheduling is performed on Java systems that support timeslicing vs. scheduling on Java systems that do not support timeslicing. 15.9 Why would a thread ever want to call yield? 15.10 What aspects of developing Java applets for the World Wide Web encourage applet designers to use yieldand sleep abundantly? 15.11 If you choose to write your own start method, what must you be sure to do to ensure that your threads start up properly? 15.12 Distinguish among each of the following means of pausing threads: a) busy wait b) sleep c) blocking I/O 15.13 Write a Java statement that tests if a thread is alive. 15.14 a) What is multiple inheritance? b) Explain why Java does not offer multiple inheritance. c) What feature does Java offer instead of multiple inheritance? d) Explain the typical use of this feature. e) How does this feature differ from abstract classes? 15.15 Distinguish between the notions of extendsand implements. 15.16 Discuss each of the following terms in the context of monitors: a) monitor b) producer c) consumer d) wait e) notify f) InterruptedException g) synchronized 15.17 (Tortoise and the Hare) In the Chapter 7 exercises, you were asked to simulate the legendary race of the tortoise and the hare. Implement a new version of that simulation, this time placing each of the animals in a separate thread. At the start of the race call the start methods for each of the threads. Use wait, notify and notifyAll to synchronize the animals activities. 15.18 (Multithreaded, Networked, Collaborative Applications) In Chapter 17, we cover networking in Java. A multithreaded Java application can communicate concurrently with several host computers. This creates the possibility of being able to build some interesting kinds of collaborative applications. In anticipation of studying networking in Chapter 17, develop proposals for several possible multi- threaded networked applications. After studying Chapter 17, implement some of those applications. 15.19 Write a Java program to demonstrate that as a high-priority thread executes, it will delay the execution of all lower priority threads. 15.20 If your system supports timeslicing, write a Java program that demonstrates timeslicing among several equal-priority threads. Show that a lower priority thread s execution is deferred by the timeslicing of the higher-priority threads. 15.21 Write a Java program that demonstrates a high priority thread using sleep to give lower priority threads a chance to run.
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Web hosting reseller - Chapter 15 Multithreading 887 Java, a Thread object

Wednesday, September 19th, 2007

Chapter 15 Multithreading 887 Java, a Thread object can use this pattern in method run. For instance, method run can contain an infinite loop that is terminated by some state change upon termination, method run can invoke a private method responsible for stopping any other spawned threads (phase one). The thread then terminates after method run terminates (phase two). In Discovering Design Patterns Section 17.10, we return to the gang-of-four design patterns. Using the material introduced in Chapters 16 and 17, we identify those classes in package java.io and java.net that use design patterns. SUMMARY Computers perform operations concurrently, such as compiling a program, printing a file and receiving e-mail messages over a network. Programming languages generally provide only a simple set of control structures that enable programmers to perform one action at a time, then proceed to the next action after the previous one is finished. The concurrency that computers perform today is normally implemented as operating system primitives available only to highly experienced systems programmers. Java makes concurrency primitives available to the programmer. Applications contain threads of execution, each thread designating a portion of a program that may execute concurrently with other threads. This capability is called multithreading. Java provides a low-priority garbage collector thread that reclaims dynamically allocated memory that is no longer needed. The garbage collector runs when processor time is available and there are no higher priority runnable threads. The garbage collector runs immediately when the system is out of memory to try to reclaim memory. Method run contains the code that controls a thread s execution. A program launches a thread s execution by calling the thread s start method, which, in turn, calls method run. Method interruptis called to interrupt a thread. Method isAlive returns trueif starthas been called for a given thread and the thread is not dead (i.e., the run method has not completed execution). Method setName sets the name of the Thread. Method getName returns the name of the Thread. Method toString returns a String consisting of the name of the thread, the priority of the thread and the thread s group. Threadstatic method currentThread returns a reference to the executing Thread. Method join waits for the Threadon which join is called to die before the current Thread can proceed. Waiting can be dangerous; it can lead to two serious problems called deadlock and indefinite postponement. Indefinite postponement is also called starvation. A thread that was just created is in the born state. The thread remains in this state until the thread s startmethod is called; this causes the thread to enter the ready state. A highest priority-ready thread enters the running state when the system assigns a processor to the thread. A thread enters the dead state when its run method completes or terminates for any reason. The system eventually will dispose of a dead thread.
If you are searching for cheap webhost for your web application, please visit MySQL5 Web Hosting services.

886 Multithreading Chapter 15 15.13 (Optional) Discovering Design (Web hosting services)

Tuesday, September 18th, 2007

886 Multithreading Chapter 15 15.13 (Optional) Discovering Design Patterns: Concurrent Design Patterns Many additional design patterns have been created since the publication of the gang-of-four book, which introduced patterns involving object-oriented systems. Some of these new patterns involve specific object-oriented systems, such as concurrent, distributed or parallel systems. In this section, we discuss concurrency patterns to conclude our discussion of multithreaded programming. Concurrency Design Patterns Multithreaded programming languages such as Java allow designers to specify concurrent activities that is, those that operate in parallel with one another. Designing concurrent systems improperly can introduce concurrency problems. For example, two objects attempting to alter shared data at the same time could corrupt that data. In addition, if two objects wait for one another to finish tasks, and if neither can complete their task, these objects could potentially wait forever a situation called deadlock. Using Java, Doug Lea1 and Mark Grand2 created concurrency patterns for multithreaded design architectures to prevent various problems associated with multithreading. We provide a partial list of these design patterns: The Single-Threaded Execution design pattern (Grand, 98) prevents several threads from invoking the same method of another object concurrently. In Java, the synchronized keyword (discussed in Chapter 15) can be used to apply this pattern. The Guarded Suspension design pattern (Lea, 97) suspends a thread s activity and resumes that thread s activity when some condition is satisfied. Lines 137 147 and lines 95 109 of class RandomCharacters (Fig. 15.17) use this design pattern methods wait and notify suspend and resume, respectively, the program threads, and line 98 toggles the variable that the condition evaluates. The Balking design pattern (Lea, 97) ensures that a method will balk that is, return without performing any actions if an object occupies a state that cannot execute that method. A variation of this pattern is that the method throws an exception describing why that method is unable to execute for example, a method throwing an exception when accessing a data structure that does not exist. The Read/Write Lock design pattern (Lea, 97) allows multiple threads to obtain concurrent read access on an object but prevents multiple threads from obtaining concurrent write access on that object. Only one thread at a time may obtain write access on an object when that thread obtains write access, the object is locked to all other threads. The Two-Phase Termination design pattern (Grand, 98) uses a two-phase termination process for a thread to ensure that a thread frees resources such as other spawned threads in memory (phase one) before termination (phase two). In 1. D. Lea, Concurrent Programing in Java, Second Edition: Design Principles and Patterns. Massachusetts: Addison-Wesley. November 1999. 2. M. Grand, Patterns in Java; A Catalog of Reusable Design Patterns Illustrated with UML. New York: John Wiley and Sons, 1998.
Check Tomcat Web Hosting services for best quality webspace to host your web application.

Chapter 15 (Yahoo free web hosting) Multithreading 885 to ride the Elevator,

Tuesday, September 18th, 2007

Chapter 15 Multithreading 885 to ride the Elevator, to class Person. We assign maxTravelTime a value of 10 minutes (10* 60seconds). We will use these class diagrams to implement our Java code in Appendix H, but we will continue making subtle Java-specific adjustments to code. In the appendices, for each class, we create methods that access object references and implement interface methods. In Thinking About Objects Section 22.9, we design the view the display of our model. When we implement this display in Appendix I, we will have a fully functional 3,594-line elevator simulation. Person -ID : Integer -moving : Boolean = true -location : Location -maxTravelTime : Integer = 10 * 60 + doorOpened( ) : void ElevatorShaft Bell ElevatorModel -numberOfPeople : Integer = 0 + ringBell( ) : void Light -lightOn : Boolean = false + turnOnLight( ) : void + turnOffLight( ) : void + addPerson( ) : void Button - pressed : Boolean = false + resetButton( ) : void + pressButton( ) : void Door -open : Boolean = false + openDoor( ) : void + closeDoor( ) : void Floor + getButton( ) : Button + getDoor( ) : Door Elevator -moving : Boolean = false - summoned : Boolean = false -currentFloor : Location - destinationFloor : Location - travelTime : Integer = 5 + ride( ) : void + requestElevator( ) : void setMoving( Boolean ) : void + getButton( ) : Button + getDoor( ) : Door Location -locationName : String # setLocationName( String ) : void + getLocationName( ) : String + getButton( ) : Button + getDoor( ) : Door Fig. 15.11Final class diagram with attributes and operations. 15.11
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Hp web site - 884 Multithreading Chapter 15 Creates Light ElevatorModel Floor

Monday, September 17th, 2007

884 Multithreading Chapter 15 Creates Light ElevatorModel Floor ElevatorShaft Bell Person Elevator Presses 2 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0..* 1 1 1 1 2 Signals to move ResetsOpens / Closes Occupies Signals arrival Turns on/off Rings Door Button Location Signals arrival Signals arrival Signals arrival Signals arrival Signals arrival Informs of opening 1 1 1 1 1 1 1 1 1 1 Fig. 15.10Final class diagram of the elevator simulation 15.10 Figure 15.11 presents the attributes and operations for all classes in Fig. 15.10. We use both diagrams to implement the model. We have omitted method enterElevator and exitElevator from class Elevator, because as discussed in the interaction diagrams, method ride appears to handle the Person s entering, riding and exiting the Elevator. In addition, we have replaced method departElevator with private method setMoving, because according to Fig. 15.9, method setMoving provides the service that allows the Elevator to depart from a Floor. We also include private attribute maxTravelTime, which represents the maximum time the Personwill wait
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Chapter 15 Multithreading 883 than the (Sex offenders web site) request, the

Monday, September 17th, 2007

Chapter 15 Multithreading 883 than the request, the Elevator must move to the Floor on which the Person is waiting. To save space, the note informing that the Elevator moves to the other Floor represents this sequence (We will construct this sequence momentarily when we discuss how the Person rides the Elevator to the other Floor.) When the Elevator travels to the other Floor, the branched sequence merges with the original sequence in the Elevator s lifeline, and the elevatorDoor sends an elevatorArrived message to the elevatorDoor upon arrival. If the Elevator is on the same Flooras the request, the elevatorDoor immediately sends an elevatorArrived message to the elevatorDoorupon arrival. The elevatorDoor receives the arrival message and opens the Dooron the arrival Floor. This door sends a doorOpened message to the Person that Person then enters the Elevator. The Person then presses the elevatorButton, which sends a button- Pressed event to the Elevator. The Elevator gets ready to leave by calling its private method setMoving, which changes the Elevator s boolean attribute moving to true. The Elevator then closes the elevatorDoor, which closes the Door on that Floor. The Person then rides the Elevator by invoking the Elevator s synchronized method ride. As in the collaboration diagram, the {concurrent} keyword placed after method ride indicates the method is synchronized, when implemented in Java. The remainder of the diagram shows the sequence after the Elevator s arrival at the destination Floor(also described in Fig. 15.9). Upon arrival, the Elevator stops moving by calling private method setMoving, which sets attribute moving to false. The Elevator then sends an elevatorArrived message to the ElevatorDoor, which opens the Door on that Floor and sends the Person a doorOpened message. Method doorOpened wakes the sleeping Person s thread by invoking method interrupt, causing method ride to terminate and return the Person s thread to the ready state. The Person exits the simulation shortly afterwards. Note the large X at the bottom of the Person s lifeline. In a sequence diagram, this X indicates that the associated object destroys itself (in Java, the Person object is marked for garbage collection). Our Final Class Diagram The integration of multithreading in our elevator model concludes the design of the model. We implement this model in Appendix H. Figure 15.10 presents the complete class diagram we use when implementing the model. Note that the major difference between the class diagrams of Fig. 15.10 and Fig. 10.31 is the presence of active classes in Fig. 15.10. We have established that classes Elevator and Personare active classes. However, the problem statement mentioned that if a person neither enters nor requests the elevator, the elevator closes its door. Having discussed multithreading, we believe that a better requirement would be for the Doors to close automatically (using a thread) if they have been open for more than a brief period (e.g., three seconds). In addition, although not mentioned in the problem statement, the Lights should turn off automatically currently, the Lights turn off only when the Elevator departs from a Floor. We mark the Doors and Lights as active classes to handle this change. We implement this change in Appendix H.
Searching for affordable and proven webhost to host and run your servlet applications? Go to Linux Web Hosting services and you will find it.


guns ringtones free roses n

Over guns ringtones free roses n five years several dozen mobile operators (carriers) have abandoned networks on TDMA and CDMA technologies, switching over to GSM.

afi ringtones

[21] In other countries, evidence about the physical location of afi ringtones at a given time has been introduced by triangulating the individual’s cellphone between several cellphone towers.

free ringtones qwest

Some providers allow users to create their own music tones, either with free ringtones qwest composer” or a sample/loop arranger (such as the MusicDJ in many Sony Ericsson phones).

ringtone boony

[56][57][58] While ringtone boony claim of damage to bees was widely reported, the corrections to the story were almost non-existent in the media.

ringtones free kyocera

A working group made up of Finnish telephone companies, public transport operators and communications authorities has launched ringtones free kyocera to remind ringtones free kyocera users of courtesy, especially when using mass transit—what to talk about on the phone, and how to.

harley ringtones

On harley ringtones basis, India is the largest growth market, adding about 6 million harley ringtones s every month.

jones ringtones no tom subscription

Most early content for mobile tended to be copies of legacy media, such as jones ringtones no tom subscription advertisement or the TV news highlight video clip.

ringtones free wrestling

Some book shops, libraries, bathrooms, cinemas, doctors’ offices and places of worship prohibiting their use, so that other patrons will not be disturbed by conversations.

free uk ringtones oldies

The phones have free uk ringtones oldies transceiver that transmits voice and data to the nearest cell sites, normally not more than 8 to 13 km (approximately 5 to 8 miles) away.

ringtones katana

Studies have shown that talking on ringtones katana can reduce the cognitive resources that the driver can apply to the driving task, and may thus lead to dangerous situations[citation needed].

882 Multithreading Chapter 15 person : Person floorButton (Post office web site)

Monday, September 17th, 2007

882 Multithreading Chapter 15 person : Person floorButton : Button elevatorButton : Button elevator: Elevator floorDoor : Door elevatorDoor : Door [Elevatoron pressButton( ) doorOpened( ) requestElevator( ) elevatorArrived( ) pressButton( ) openDoor( ) [Elevator on same Floor of request] person enters elevator person waits for elevator opposite Floor of request] buttonPressed( ) elevator travels to other floor ride( ) {concurrent} closeDoor( ) closeDoor( ) setMoving( true ) person exits elevator interrupt( ) person rides elevator terminate method ride elevator travels 5 seconds setMoving( false ) doorOpened( ) elevatorArrived( ) openDoor( ) Fig. 15.9Sequence diagram for a single Personchanging floors in system. 15. Note the split in flow for the Elevatorafter being requested; the flow of execution depends on which Floorgenerated the request. If the Elevatoris on a different Floor
Looking for affordable and reliable webhost to host and run your business application? Then look no more and go to servlet web hosting services.

Chapter 15 Multithreading 881 The ridingPassenger does not (Web hosting domain)

Sunday, September 16th, 2007

Chapter 15 Multithreading 881 The ridingPassenger does not need to send the exitElevator message (message 3.3.1) to the Elevator, because the waitingPassenger cannot invoke ride until the ridingPassenger releases the Elevator s monitor the ridingPassenger releases the monitor when the ridingPassengerthread exits method ride after calling its interrupt method. Therefore, the Person thread s interrupt method is equivalent to the exitElevator method (except that the Person sends itself the interrupt message), and we can substitute method interrupt for method exitElevator. Also, we can combine methods ride and enterElevator to handle both entering and riding the Elevator our system needs only method ride, which allows a Person to obtain a monitor on the Elevator. As we implement our model in Appendix H, we use our collaboration diagram to help generate code in Java however, we will make subtle Java-specific adjustments to our code to guarantee that the Persons enter and exit the Elevator correctly. Sequence Diagrams We now present the other type of interaction diagram, called a sequence diagram. Like the collaboration diagram, the sequence diagram shows interactions among objects; however, the sequence diagram emphasizes how messages are sent between objects over time. Both diagrams model interactions in a system. Collaboration diagrams emphasize what objects interact in a system, and sequence diagrams emphasize when these interactions occur. Figure 15.9 is the sequence diagram for a Person changing floors. A rectangle enclosing the name of an object represents that object. We write object names in sequence diagrams using the same convention we have been using with collaboration diagrams. The dotted line extending down from an object s rectangle is that object s lifeline, which represents the progression of time. Actions occur along an object s lifeline in chronological order from top to bottom an action near the top of a lifeline happens before an action near the bottom. We provide several notes in this diagram to clarify where the Person exists in the simulation. Note that the diagram includes several dashed arrows. These arrows represent return messages, or the return of control to the sending object. Every message ultimately yields a return message. Showing return messages is not mandatory in a sequence diagram we show return messages for clarity. Message passing in sequence diagrams is similar to that in collaboration diagrams. An arrow extending from the object sending the message to the object receiving the message represents a message between two objects. The arrowhead points to the rectangle on the receiving object s lifeline. As previously mentioned, when an object returns control, a return message represented as a dashed line with an arrowhead extends from the object returning control to the object that initially sent the message. The sequence in Fig. 15.9 begins when a Person presses a Buttonon a Floorby sending message pressButton to that Button. The Button then requests the Elevator by sending message requestElevator to the Elevator. The Person must wait for the Elevatorto process this message before continuing. However, the Person does not need to wait for the Elevator s arrival before proceeding with other actions. In our simulation, we force the Personto wait, but we could have had the Person perform other actions, such as read a newspaper, sway back and forth or place a call on a cell phone as the Elevator travels to the Floor of the Person.
Check Tomcat Web Hosting services for best quality webspace to host your web application.