Developing Java Beans { lowThreshold = low; }
Developing Java Beans // clone the queue so we don’t tie up anyone else Vector tempQueue; synchronized (queue) { tempQueue = (Vector)queue.clone(); // delete the ones we have from the real queue queue.removeAllElements(); } // empty the queue in FIFO order and notify listener while (!tempQueue.isEmpty()) { PollEvent evt = (PollEvent)tempQueue.elementAt(0); tempQueue.removeElementAt(0); listener.pollSent(evt); } } } } We have to make some changes to the Watcher class as well. We need an instance of the PollerAdapter class, and the Watcher constructor will be modified to use the adapter instead of being the PollerListener itself. Notice that the Watcher still implements the PollerListener interface because that is the way the adapter forwards the events to it. The code for the Watcher now looks like this: class Watcher implements PollerListener { // the poller objectprotected Poller poller = new Poller(); // the adapter protected PollerAdapter adapter; // the constructor public Watcher() { // create the adapter adapter = new PollerAdapter(this, poller); } // the event handler simulates work by sleeping for // 2 seconds before returning public void pollSent(PollEvent evt) { try { System.out.println(”Received Event Number: ” + evt.getValue()); Thread.sleep(2000); } catch (InterruptedException e) { } } } page 49
Note: If you are looking for cheap and reliable provider to host and run your servlet application check Vision servlet hosting services