Forgive me if this question has been asked already, I searched but couldn't find anything. I have a Swing app that has to run about 15 queries and display the data, pretty simple. Some of the queries take mere milliseconds while some of them take several minutes to return the data. I have the queries set to run each time a Swing timer fires. My ideal situation would be to have the data update every 5 seconds but that's not possible with the slower queries. I broke the queries into 2 groups, the really fast ones and the really slow ones. I even set them on 2 different timers on different threads, the fast ones run every 5 seconds, the slow ones run every 5 minutes. The problem is that when the slow queries are running the fast queries wait until the slow queries finish before they run again, even on different threads. I switched to use the SwingWorker class and am having the same problem. I've tried everything....using separate DB connections for each query group, putting the queries into 2 separate classes with separate connections and calling one main from the other but it always seems to bottleneck at the database (Oracle). The only way I've found a way around this is to start the 2 main classes completely independent of each other. Now each set of queries can run at the same time but I've had to split my Swing app into 2 separate forms and it's a pain in the butt because I'm trying to learn Web Start now. Sorry this is so long but I wanted to make my problem clear. I hope there's an easy solution because I can't seem to find it.
Thanks for any advice!
Michael J Bruesch<br /><i>I code, therefore I am.</i>
Joined: Mar 22, 2005
All javax.swing.Timer objects use the same thread; the javadocs for that class actually mention that. That's why you're seeing serialized execution.
If you want multiple threads executing independently of one another, have a look at the java.util.Timer and TimerTask classes. Each of those Timer objects has its own thread, thus you get independent (quasi-parallel) execution.
You're absolutely right, I didn't see that at first somehow. Everywhere I went reading about using timers for swing apps everyone said "Use the Swing Timer!" and so I did without question I guess. I'll try the util Timer and see how it works. Thanks Ulf!!