Solved

Multi-Threaded Application

Posted on 2004-08-21
6
176 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hibernate Not Rolling Back When something fails in a stored procedure 2 52
java 8 lambda expresssions exception handling 3 75
print map entry 34 55
tomcat not starting 6 32
For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now