Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #4576
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.java.gui |
| Subject | Re: Synchronization when collecting data from the EDT? |
| Date | 2011-06-05 23:47 -0400 |
| Organization | The Wasteland |
| Message-ID | <nospam-0D155A.23474105062011@news.aioe.org> (permalink) |
| References | <MdAGp.362$SG4.2@newsfe03.iad> <isg8ng$i6u$1@dont-email.me> <8jPGp.40014$Vp.14760@newsfe14.iad> |
In article <8jPGp.40014$Vp.14760@newsfe14.iad>,
Knute Johnson <nospam@knutejohnson.com> wrote:
> On 06/05/2011 08:52 AM, Daniele Futtorovic wrote:
> > On 05/06/2011 02:38, Knute Johnson allegedly wrote:
> >> If you want to remove some data from the EDT and use it in another
> >> thread, does EventQueue.invokeLater() or invokeAndWait()
> >> constitute happens before? I don't think it does, so in that
> >> case, if you need to access some data from your GUI components and
> >> use that data on another thread there has to be some
> >> synchronization.
> >
> > Knute, sorry for being dense, but I don't quite get how this
> > situation differs from any other "passing" of data across threads,
> > nor how #invokeLater() or #invokeAndWait() enter into it as
> > something else than your regular parallel ("worker" or whatever)
> > thread.
> >
> > Could you indulge me and shed some light, please?
>
> I don't know that it does, I guess I was hoping that when Sun wrote
> invokeLater and AndWait that they assumed that you were getting there
> from another thread and put some sort of synchronization in. And
> maybe I'm looking for some insight as to how you would do this any
> other way. I still think that invokeAndWait has problems if the
> current thread is interrupted before execution reaches the
> synchronized block in the Runnable.
Focusing on invokeAndWait() [1], I understood it to be the standard way
to wait for data to arrive on the EDT. In particular, it promises to
block until the supplied Runnable's run method has been called on the
EDT. I don't understand why the Runnable needs a synchronized block.
A widely used implementation queues the Runnable and waits [2], using a
private AWTInvocationLock. The Runnable, wrapped in an InvocationEvent,
is subsequently dispatched [3]. When finished, the same
AWTInvocationLock is used to notifyAll().
Of the ways a thread can exit wait() [4], an InterruptedException
appears to be the only one to worry about. It looks like
InvocationEvent is always set to catch Throwable, so you'll have to
catch InvocationTargetException, too. Finally, invokeAndWait() doesn't
call wait() in a loop, as recommended [4]; but I don't think the
calling thread cares if it's not scheduled immediately on waking [5].
Having said that, I see that the Swing tutorial no longer uses
invokeAndWait() in this context. Instead, it focuses on SwingWorker
[6], which can be launched from any thread.
[1]<http://download.oracle.com/javase/6/docs/api/java/awt/EventQueue.html>
[2]<http://kickjava.com/src/java/awt/EventQueue.java.htm>
[3]<http://kickjava.com/src/java/awt/event/InvocationEvent.java.htm>
[4]<http://download.oracle.com/javase/6/docs/api/java/lang/Object.html>
[5]<http://stackoverflow.com/questions/1461913>
[6]<http://download.oracle.com/javase/6/docs/api/javax/swing/SwingWorker.html>
[7]<http://stackoverflow.com/questions/4637725>
--
John B. Matthews
trashgod at gmail dot com
<http://sites.google.com/site/drjohnbmatthews>
Back to comp.lang.java.gui | Previous | Next — Previous in thread | Next in thread | Find similar
Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-04 17:38 -0700
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-04 17:50 -0700
Re: Synchronization when collecting data from the EDT? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-05 17:52 +0200
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-05 10:47 -0700
Re: Synchronization when collecting data from the EDT? "John B. Matthews" <nospam@nospam.invalid> - 2011-06-05 23:47 -0400
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-05 22:11 -0700
Re: Synchronization when collecting data from the EDT? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-06 14:31 +0200
Re: Synchronization when collecting data from the EDT? "John B. Matthews" <nospam@nospam.invalid> - 2011-06-06 23:03 -0400
Re: Synchronization when collecting data from the EDT? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-07 18:51 +0200
Re: Synchronization when collecting data from the EDT? "John B. Matthews" <nospam@nospam.invalid> - 2011-06-07 13:38 -0400
Re: Synchronization when collecting data from the EDT? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-08 00:10 +0200
Re: Synchronization when collecting data from the EDT? "John B. Matthews" <nospam@nospam.invalid> - 2011-06-07 23:51 -0400
Re: Synchronization when collecting data from the EDT? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-10 01:17 +0200
Re: Synchronization when collecting data from the EDT? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-10 01:25 +0200
Re: Synchronization when collecting data from the EDT? "John B. Matthews" <nospam@nospam.invalid> - 2011-06-09 22:34 -0400
Re: Synchronization when collecting data from the EDT? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-10 05:22 +0200
Re: Synchronization when collecting data from the EDT? markspace <-@.> - 2011-06-10 08:04 -0700
Re: Synchronization when collecting data from the EDT? "John B. Matthews" <nospam@nospam.invalid> - 2011-06-10 21:13 -0400
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-12 12:51 -0700
Re: Synchronization when collecting data from the EDT? markspace <-@.> - 2011-06-07 23:31 -0700
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-08 23:07 -0700
Re: Synchronization when collecting data from the EDT? "John B. Matthews" <nospam@nospam.invalid> - 2011-06-09 18:35 -0400
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-12 12:45 -0700
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-08 23:05 -0700
Re: Synchronization when collecting data from the EDT? "John B. Matthews" <nospam@nospam.invalid> - 2011-06-09 14:35 -0400
Re: Synchronization when collecting data from the EDT? Roedy Green <see_website@mindprod.com.invalid> - 2011-06-05 13:39 -0700
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-05 22:17 -0700
Re: Synchronization when collecting data from the EDT? markspace <-@.> - 2011-06-07 14:51 -0700
Re: Synchronization when collecting data from the EDT? markspace <-@.> - 2011-06-05 17:46 -0700
Re: Synchronization when collecting data from the EDT? Knute Johnson <nospam@knutejohnson.com> - 2011-06-05 22:41 -0700
Re: Synchronization when collecting data from the EDT? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-06-06 14:35 +0200
csiph-web