Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

use of SwingWorker

 
Raj Nagappan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Did anybody use the SwingWorker pattern to coordinate retrieval of results on the client, or did you just execute within the AWT Event thread? Strictly speaking we should be using a separate thread but I feel it may be overkill for this assignment. Your thoughts?

Raj.
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Nagappan:
Hi,

Did anybody use the SwingWorker pattern to coordinate retrieval of results on the client, or did you just execute within the AWT Event thread? Strictly speaking we should be using a separate thread but I feel it may be overkill for this assignment. Your thoughts?

Raj.


Hi, Raj. I use just the Swing thread and I document my decision. There is no requirement for multi-threaded Swing, so documenting your decision should be fine, I think.
 
peter wooster
Ranch Hand
Posts: 1033
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Raj Nagappan:
Hi,

Did anybody use the SwingWorker pattern to coordinate retrieval of results on the client, or did you just execute within the AWT Event thread? Strictly speaking we should be using a separate thread but I feel it may be overkill for this assignment. Your thoughts?

Raj.


There is no need to use a pool of SwingWorkers, but you should use seperate threads for the database access to keep the GUI responsive, even if there is a network delay. I start a new thread for each business operation, when the business op completes I use SwingUtilities.invokeLater to update the GUI.
 
Raj Nagappan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by peter wooster:

...you should use seperate threads for the database access to keep the GUI responsive, even if there is a network delay. I start a new thread for each business operation, when the business op completes I use SwingUtilities.invokeLater to update the GUI.


This sounds like a good, simple enough idea for me - I'll try it. Thanks. BTW I've noticed that a lot of people passing have lost marks on the GUI, so I'm trying to make it fairly good whilst not gold-plating.

Raj.
 
Raj Nagappan
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

I'm trying out the simple worker thread idea in my GUI. I have several methods that each call the server for different information, e.g.

For the most part the code for each of these methods is identical, except lines such as (A) and (B) above. Does anyone know a reasonably straightforward way of templating this code so that I don't have 5 or 6 methods that are almost carbon copies of each other?

Raj.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic