Developing Java Beans { lowThreshold = low; }

Developing Java Beans You can see from this output that the Poller thread is being held up by the Watcher object. The Poller thread is supposed to be looping every 200 milliseconds to update the counter, printing its message every third update. So we would expect to see a few “Value: x” messages for each “Received Event: x” message. This is clearly not happening. We can correct this by introducing an asynchronous queuing adapter between the Poller and Watcher objects. This adapter queues the events received from the Poller, and it fires the events to the Watcher from its own notification thread, allowing the Poller to continue its work. The code for the PollerAdapter class is shown below: class PollerAdapter extends Thread implements PollerListener { // the event queueprotected Vector queue = new Vector(); // the real listener protected PollerListener listener; public PollerAdapter(PollerListener l, Poller p) { // save a reference to the target listener listener = l; // register myself as the event listener try { p.addPollerListener(this); } catch (TooManyListenersException e) { } // start my thread start(); } // receive events public synchronized void pollSent(PollEvent e) { // add an element to the queue synchronized (queue) { queue.addElement(e); } this.notify(); } // the run loop of the thread public void run() { // loop forever for (;;) { // suspend until there is work to do try { this.wait(); } catch (Exception e) { } page 48
Note: If you are looking for cheap and reliable provider to host and run your servlet application check Vision servlet hosting services

Comments are closed.