• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing Worker

 
Liviu Carausu
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I'm thinking about using the SwingWorker included in the Java 6
for making the remote calls outside of the Swing processing thread.
Do you think this is a good ideea ?
I choose to make the remote calls outside the Swing thread because
they can freeze the GUI in case that they are hanging...
Do you think that using the SwingWorker included in Jdk 6 is better that using own solution with SwingUtlities.invokeLater ? Normally they said in the specifications that we must use what comes with Java and don't reinvent the wheel....
Thanks for any eventual responses...
Liviu
 
Romeo Son
Ranch Hand
Posts: 92
Android Eclipse IDE Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Liviu,

As I use java 5 to develop my assignment, I cannot use SwingWorker. However, I also put the remote calls on worker threads to have a responsive GUI. When the worker thread finishes, I update the table with SwingUtilities.invokeLater().

Because Swing is a single threaded GUI toolkit, you must update all swing components only on AWT Event thread (with invokeLater() or invokeAndWait(), depending on the situation).

I didn't study much the SwingWorker class that comes with Java 6, but I think it combines the two features that I described previously.

Hope this helps.

Regards,

Romeo
 
Mihai Radulescu
Ranch Hand
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Liviu

I don't think that a multi-thread support for Swing will bring more points, I think that in this way you only make your code more complex (remember the junior programmer issue). More , every multithread feature requires a lot of test and even so you can have some uncovered ugly "bubu"s.

Regards,
M
 
Romeo Son
Ranch Hand
Posts: 92
Android Eclipse IDE Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mihai,

Maybe one of the reasons many guys don't get max points on GUI is that they didn't put the remote calls on worker threads. This is a main principle in GUI design so that you have a responsive application. Try to have 200 records instead of 28 and see how your GUI freezes when you fetch them in networked mode.

Regards,

Romeo
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic