Solved

Multi-Threaded Application

Posted on 2004-08-21
6
178 Views
Last Modified: 2010-03-31
I have what is probably a common problem that many of you have experienced.  I've been coding in Java for only 8 or 9 months so I'm just dangerous enough to cause myself a problem every now and then.  What I'm experiencing is the following:

I've written an application to maintain parts inventory for our company.  It connects to a sql database to retrieve information and every query to the database is triggered by a user action of one sort or another.  On rather large queries that take a little time to process and return data, I would like my swing interface to not stop updatting and still allow user-interaction.

What I "thought" my solution would be is the following:

I implemented runnable on my main-window application (which has several dozen smaller JPanel extended classes within a cardlayout) and then in my main, I just created an instance of the main window class and called .run (which contains MainClass.show() ).

Any ideas?

Thanks,
David
0
Comment
Question by:lomidien
  • 2
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:91mustang
ID: 11861418
Just run the larger queries in a seperate thread. that may work for you, just a thought
0
 

Author Comment

by:lomidien
ID: 11861626
That handles the queries part of the problem, I believe.  Since I'm already asking about the topic though, what about window refreshing issues (not related to the queries themselves).  What is the best way to go about making the main window threaded so that calls within child windows do not cause the overall application to "freeze" or not repaint properly?

Thanks,
David
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
ID: 11861702
Hi lomidien,

all repaints and processing in swing components should be made in the event-dispatching thread so it won't cause other components to wait till the main thread finishes. Take a look at the following tutorials:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html
http://java.sun.com/products/jfc/tsc/articles/threads/threads2.html
http://java.sun.com/products/jfc/tsc/articles/threads/threads3.html

Regards
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 

Author Comment

by:lomidien
ID: 11861764
Perfect.  Exactly what I was looking for.

Thanks
0
 
LVL 4

Expert Comment

by:91mustang
ID: 11862131
>>That handles the queries part of the problem

Well why not a points split?
0
 
LVL 35

Expert Comment

by:girionis
ID: 11862972
:)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
tomcat not starting 6 70
MySqlDump not dumping triggers 1 43
American Express @Work site and Java 4 33
IBM TS2900 (3572) Tape Autoloader Java? 12 19
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question