|
So everybody seems nervous about doing multithreading on GUIs. It seems some people thinks Swing should be thread safe.
That's nonsense! There's not a single GUI in the market (AFAIK) that is thread safe!. And there's a simple reason for that: it's not possible or desireable to build one!
In fact Microsoft's MFC, GTK, wxWidgets (aka wxWindows), SWT and QT are not threadsafe. (and you could include Motif 2.0, Athena, Xt and some other older toolkits here)
All these toolkits use a thread to dispatch events to widgets (the event-loop thread) and, maybe, some others for paiting. Same thing in Swing.
So if you perform heavy-duty, time-consuming, stuff in the event loop thread you pause sending events (and/or repainting) and resume later after the time-consuming stuff ends. Meanwhile your GUI seems to hang, does not respond (because no events are being processed) and, depending on the toolkit, may even stop painting the widgets.
It's that simple. And it has to be. There's no workaround. You have to live with it.
Now, if you investigate a little bit on how MFC, GTK, wxWidgets, SWT or any other ease this task you'll probably find out that the new SwingWorker is just a piece of cake.
And, with the addition ( JSR 166) of the excellent Doug Lea's concurrent utilities to JDK 5.0, the rebranded SwingWorker offers new possibilities to boost your GUI performance and your productivity.
I'm for holidays today, too weeks around Spain, but I promise posting some sample code of SwingWorker by the end of the month (and maybe some photos too).
Meanwhile I'll accept suggestions for examples. Please include a comment below about what sort of thing you would like me to work on the example. Should be simple enough for a short example. Hints: invoke an EJB on the background? invoke a web service? retrieve content from a RSS feed? a JTree for a filesystem that seeks the nodes (files) in the background?
Happy Swinging!!
|
Enviado por Santhosh Kumar en julio 05, 2005 a las 06:16 PM CEST #
Enviado por 213.140.27.85 en julio 06, 2005 a las 03:47 PM CEST #