433 Final Exam, May 19thDon’t panic.You may also avail yourself of the punt rule. Write down punt for a question, and your grade is 1/5 ofthe points for the question.There are two questions; check the back size of the paper.1. (20 points) Bakery algorithm for first-in, first-out queuingIn many bakeries, when you enter the bakery to go to a machine gives out slips of paper with numberson them. Behind the counter, there is a display of the last number being served. When one of thepeople behind the counter is ready for the next tranaction, they increment the number being served,and then help the person with that number. In this way, people are served in the order in which theytook pieces of paper.This question requires you to reimplement the OnePlaceBuffer interface we used in our first day quiz.However, if multiple threads block trying to call take(), they should return in FIFO (first-in, first-out)order. Calls to put(Object o) do not have to complete in FIFO order.We are going to be ignoring interrupts, so InterruptedExceptions have been removed from the interface.You are encouraged to use the Bakery algorithm to implement this, although any other valid imple-mentation is OK.Your design should be such that no CPU power is used when no activity is taking place, and methodsreturn as quickly as possible. In other words, you should not depend upon spin waits, yielding orsleeping.package cmsc433;public interface OnePlaceBuffer {public Object take();public void put(Object o);}2. (10 points) Short answer:• There are two basic approaches/APIs for dealing with XML documents. In class, we discussedthese as the SAX and the DOM approaches. Briefly describe the differences and relative advan-tages/disadvantages of these approaches.• Why might you wish to restrict the machines and ports that untrusted code can connect to?• You’ve calculated/measured that the data structures in use by your program require 100 + 10nKbytes at any one time to handle n warehouses. Your program will be doing a reasonable amountof memory allocation (with some of the previously allocated memory becoming unreachable andtherefore garbage), so you need to worry about the cost of garbage collection.For 1000 warehouses, which number is best estimate for the amount of heap memory your programwould need to run in so that garbage collection would be efficient? Explain your choice:– 10 Megabytes– 15 Megabytes– 25 Megabytes– 50 Megabytes3. (10 points) Mix and matchFor each item in the left column, match it with the problem or domain in the right column for whichit would most likely be useful.Each item should be paired no more than once. There is one item in each column that should not bepaired at all (in other words, there is one bogus entry in each column).1Technology Problem1 Interrupts a Abstract syntax trees2 Multicast b Debuggers and IDEs3 Observer pattern c Fault tolerence4 Reflection d Finding peers5 Singleton pattern e GUIs6 Visitor pattern f Saving state7 XML g Shutting down4. (15 points) Distributed computing:One of the design choices in RMI was to force every method in a remore interface to throw a Remote-Exception and make RemoteException a declared exception (so that if you call a method that couldthrow a remote exception, you must either catch the exception or declare that you could throw it).An alternative would be to make it be a RuntimeException, like a NullPointerException.Discuss whether the decision made in RMI is a good or bad decision, and why. Feel free to refer to theideas discussed in the A Note on Distributed Computing.5. (10 points) Factory methods There are two basic approaches to allowing users to create instances:• public constructors• public static factory methods and non-public constructorsGive the relative advantages/disadvantages of these two
View Full Document