The Source for Java Technology Collaboration
User: Password:



David Herron

David Herron's Blog

Creating multi-threaded Swing apps that consume web services

Posted by robogeek on December 03, 2007 at 11:04 AM | Comments (1)

Java is (potentially) capable of taking part in the 'Rich Internet Application' game. This is especially interesting as we finish bringing the OpenJDK project to being completely open source (instead of the open-source-but-for-a-few-encumbrances situation we have today) in that an open source Java offers the potential to be an open source answer to Flex.

A question which hovers in my mind is, does the platform truly behave right in regards to being acceptable in the role that Flash/Flex/AJAX/DHTML is filling today.

I just came across this tutorial: Creating multi-threaded Swing apps that consume web services addressing part of this question. An Internet-Aware application would be consuming multiple data services over the Internet and displaying them in an application. So how do you do that and not mess up application behavior?

One thing that seems to regularly trip up Swing developers is the single threaded model. An event listener in Swing executes on the Event Dispatch Thread (EDT) and if the listener takes too long to execute this prevents applications from repainting properly or otherwise feeling very responsive. While it might seem straightforward coding to make database or webservices calls in a listener and then show the result on the screen.. the webservice or database call will require an indeterminate amount of time (due to network traffic vagaries) and during the call the app window will not repaint properly.

The blog entry shows several ways to use SwingWorker to get around this.


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Hi David


    Thanks for a link to my article. I'm actually building an RIA platform and apps & services that go along with it, in Java6. I've been doing this for about a year now... I have lots more articles on this subject on developerlife.com.

    Browser based apps are single threaded (even with GWT and async callbacks, etc), and they are full of security holes (you can have an iframe that loads whatever from wherever)...

    I'm also working on a Task API that I will OSS very soon ... it focuses on making it easy to write swing apps, without worrying about EDT issues... and it uses a very closure-friendly programming model... The code is written and tested, just have to clean it up before open sourcing... I have lots of hooks into my platform that have to be severed... but this won't impact functionality any...

    Here's another link that maybe of interest to you - cancelling swingworker task in flight. It deals with the issues of cancelling a SwingWorker (running a background task)... my Task API will make this a breeze... but if you are coding with SwingWorker, this will help...

    Please come back and check out developerlife regularly. We have a whole series on GWT right now, but after that we plan on releasing the Task API and lots of SwingX stuff... I've been using and refining the Task API for many months now... so it should be a solid toolkit when it's released.

    You might also enjoy my rant on why Java is still an awesome platform and language to develop modern, and future applications in... I'm sick and tired of hearing how ajax will cure world hunger, and cancer ;).

    Take care
    Nazmul.

    Posted by: nazmulidris on December 04, 2007 at 10:15 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds