Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when to use threads in swing applications?

 
Abhishek Reddy
Ranch Hand
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when to use threads in swing applications? and how to improve the performance of the swing application?
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
pete stein
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 259
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11021
12
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Darryl Burke
Bartender
Posts: 5125
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Recommended reading:
Concurrency in Swing
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic