|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
In this article, I will provide the full source code to accomplish this tip. But first, let's examine the solution in more
detail. You first create an event queue class that extends the standard java.awt.EventQueue class. The new event queue contains a special timer thread for measuring the processing time for each event. It starts the
timer before dispatching an event. Then, if the event is not processed within your predetermined time limit, the timer thread
changes the cursor to an hourglass. After processing is complete, the queue changes the cursor back to the default cursor
if necessary.
Below you will find the implementation of the dispatchEvent() method for the new event queue.
14: protected void dispatchEvent(AWTEvent event) {
15: waitTimer.startTimer(event.getSource());
16: try {
17: super.dispatchEvent(event);
18: }
19: finally {
20: waitTimer.stopTimer();
21: }
22: }
All UI events go through the EventQueue.dispatchEvent() method. This method delivers the events to the correct UI components, which then process the events. As you can see, the
queue overrides the default behavior of dispatchEvent() and wraps the standard functionality of the EventQueue class in your timing routines.
Line 15 notifies your timing thread that an event is about to be dispatched so that it will begin measuring the event's execution
time. Note that you are passing the event's source -- the object to which this event will eventually be delivered. If the
timing thread determines that the event is taking too long to process, it will need to know the event's source to determine
which java.awt.Window's cursor should be changed to the hourglass.
Line 20 stops the timer and, if necessary, changes the cursor back to the default cursor. A try-finally block wraps the event dispatch because the stopTimer() method must be executed regardless of whether an exception is thrown during event processing.
The startTimer() method is very straightforward. It simply stores a reference to the event's source and notifies the timer thread.