Developing Java Beans { lowThreshold = low; }
Developing Java Beans throw new TooManyListenersException(); } listener = l; } // remove the listener public void removePollerListener(PollerListener l) { if (listener == l) { listener = null; } } // the run loop for this thread public synchronized void run() { // loop forever for (;;) { try { // we sleep for 200 milliseconds at a time this.sleep(200); // bump the counter cnt++; // every 3rd time, fire the event if ((cnt % 3) == 0) { // print out which event we’re firingSystem.out.println(”Value: ” + cnt); // fire the event if (listener != null) { listener.pollSent(new PollEvent(this, cnt)); } } } catch (InterruptedException e) { } } } } With no listener object, the Poller loops unimpeded. It bumps its counter every 200 milliseconds, and with every third update it prints its message. Now let’s introduce an object called a Watcher that implements the PollerListener interface. Whenever the event is fired on the Watcher, it prints out the value of the event it received and sleeps for 2 full seconds. This will interfere with the Poller run loop, because the synchronous delivery of events results in the Poller thread being held up by the event handling method of the Watcher object. The code for the Watcher, as well as the application code to get the whole thing started, is given below: class Watcher implements PollerListener { // the poller objectprotected Poller poller = new Poller(); page 46
Note: If you are looking for cheap and reliable provider to host and run your servlet application check Vision servlet hosting services