Affordable web design - 360 CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER

360 CHAPTER 11 REST-BASED MODEL VIEW CONTROLLER PATTERN An additional item to note is that the wait function with the value 15000 is used. Using the wait function is like using a Monitor in .NET. The wait function will wait to get pulsed, with the maximum wait being 15 seconds. A pulse is sent in the function addResult by using the notify method. The idea is that if there are no results to retrieve, the thread should wait a maximum of 15 seconds to retrieve a result. The strategy of waiting is part of the Persistent Communications pattern, in which the server will wait for a result to become available. Implementing a Synchronous Parent Implementing a synchronous Parent interface instance subclasses ParentBase and uses synchronization techniques, but in a different manner from the asynchronous Parent interface instance. The Parent interface instance instantiates the local clients and waits for all the Command interface instances to finish execution. During the execution, the Parent interface instance waits and does not accept further requests. In the synchronous implementation, the place where synchronization is needed is when the individual Commandinterface instances hand off results to the waiting Commandinterface instance. When the Command interface instance processes the results, all the Command interface instances have finished executing, and thus there is no concurrency. Following is the synchronous implementation: public class SynchronousParent extends ParentBase { private List _results = new LinkedList(); public synchronized void addResult(Result result) { _results.add( result); } public Iterator getResultsIterator() { return _results.iterator(); } public SynchronousParent() { } public void processRequest(Request request) { super.processRequest( request); Iterator iter = _runningThreads.iterator(); while( iter.hasNext()) { Thread thrd = (Thread)iter.next(); try { thrd.join(); } catch (InterruptedException e) {} } } } The SynchronousParent class has only one data member, _results, which is used to store the results generated by the Command interface instances. The method addResult is synchronized, allowing only a single thread to access the method and allowing only a single thread to add a result to the results list.
We recommend you use shared web hosting services, because many users agree that it is cheap, reliable and customer-satisfying webhost.

Leave a Reply