🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #10195

Re: Swing, Threads, and Progress meters.

#10195
From: John P. McGrath
Date: Sat, 06 Nov 1999 00:00
38 lines
2440 bytes
On Thu, 04 Nov 1999 09:55:42 +0000, Steve Horsley wrote:

Thank you for your excellent answer, Steve.  It will be very helpful.

> I would suggest that you arrange that all the model observers do not
> modify the GUI directly, but instead create a Runnable object that will
> do the work. You can then use SwingUtilities.invokeLater(Runnable r) to
> have the GUI update performed by the GUI event thread.

This is close to (but much better than) one idea I had thought of.  I was 
considering creating two event registration methods for each one I have 
now.  Listeners registered with one method would have worked the same as 
it does now, while the other would have used invokeLater() to notify the 
listener.  Your suggestion is much cleaner.

There are a few issues that must be considered with this approach.  One 
is that the GUI update code will no longer be executed when the event is 
fired.  Again, your approach is cleaner in this regard:  My approach 
required that the event information was not dependent on the current 
state of the model since when the Listener received it, the model may 
have changed.  With your approach, the Listener can determine precisely 
what information is needed to update the GUI, and queue it with the 
Runnable.

One concern I did have was with performance.  Do you have any idea what 
kind of overhead is incurred when you use invokeLater()?  From my brief 
glance at the source code, it does not look too bad, but it's hard to 
tell without actually trying it.

One possible optimization on this would be to have the listeners check 
whether they are already running on the event dispatch thread using 
EventQueue.isDispatchThread(), and perform the update without queuing if 
this returns true.

-- 
John P. McGrath
<mcgrath@enter.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID: <MPG.128da709fed5afdb989696@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <MPG.1289bc46f1d0f7aa989685@forums.borland.com> <38212c72.1261133@forums.inprise.com> <MPG.128afecc7d95098098968d@forums.borland.com> <3821581E.88C37E4C@cwcom.co.uk>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,eebaae9990e98781
X-Google-Attributes: gid111d45,public
From: John P. McGrath <mcgrath@enter.net>
Subject: Re: Swing, Threads, and Progress meters.
Date: 1999/11/06
Message-ID: <MPG.128da709fed5afdb989696@forums.borland.com>
X-Deja-AN: 545121664
References: <MPG.1289bc46f1d0f7aa989685@forums.borland.com> <38212c72.1261133@forums.inprise.com> <MPG.128afecc7d95098098968d@forums.borland.com> <3821581E.88C37E4C@cwcom.co.uk>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing