aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes when to use threads in swing applications? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "when to use threads in swing applications?" Watch "when to use threads in swing applications?" New topic
Author

when to use threads in swing applications?

Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
when to use threads in swing applications? and how to improve the performance of the swing application?


Abhishek
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19759
    
  20

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.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
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?
Abhishek Reddy
Ranch Hand

Joined: Mar 28, 2006
Posts: 259
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...




Maneesh Godbole
Saloon Keeper

Joined: Jul 26, 2007
Posts: 10519
    
    9

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.


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4658
    
    5

Recommended reading:
Concurrency in Swing


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: when to use threads in swing applications?