File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Running multiple queries concurrently Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Running multiple queries concurrently" Watch "Running multiple queries concurrently" New topic
Author

Running multiple queries concurrently

Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
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>
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 39547
    
  27
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.


Ping & DNS - updated with new look and Ping home screen widget
Michael Bruesch
Ranch Hand

Joined: Sep 23, 2001
Posts: 158
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!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running multiple queries concurrently
 
Similar Threads
Maintaining Database Connections w/ JDBC??
Threads and Synchronization examples
Tomcat 6.0.20 - session expiration not happening while machine is loaded
[Digester] End event threw exception Problem for CactusStrutsTestCase
Long running request returns no HTTP response