Mostly when an event (like a button press) requires the execution of code that takes a long time. If you don't put that into a new thread, your application appears to hang, and will not even repaint itself.
Also, I think that most of the time, threads don't improve the performance of the Swing app per se, but instead improves the responsiveness. Meaning, a background thread will not likely make a method perform any faster, but will prevent the EDT, the main Swing thread concerned with user interaction and with drawing, from getting bogged down by some long calculation, and this will allow the Swing GUI to still be able to interact with the user.
Abhishek Reddy wrote:when to use threads in swing applications? and how to improve the performance of the swing application?
Joined: Mar 28, 2006
thanks for the reply, so every event(action,item,mouse,key) has to be handled in a separate thread....
i had developed swing application using netbeans IDE, and i haven't considered to handle the event associated with swing components in a separate thread....
Is there any further steps, i have to consider for improving the performance and quick response of the swing applicaion...
Abhishek Reddy wrote:thanks for the reply, so every event(action,item,mouse,key) has to be handled in a separate thread....
Not every event, only those which are time consuming.
Or when it is intentional.
Imagine a scenario where you do not want the user to edit any stuff until he is successfully logged in.
In such kind of scenarios, you can intentionally block the UI till something has happened.
Remember though, that good usability dictates, the user should have the option of canceling any operation.