Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #4592
| From | "John B. Matthews" <nospam@nospam.invalid> |
|---|---|
| Newsgroups | comp.lang.java.gui |
| Subject | Re: Synchronization when collecting data from the EDT? |
| Date | 2011-06-09 18:35 -0400 |
| Organization | The Wasteland |
| Message-ID | <nospam-0F6952.18350809062011@news.aioe.org> (permalink) |
| References | (4 earlier) <TjZGp.40183$Vp.29218@newsfe14.iad> <nospam-7A4754.23033306062011@news.aioe.org> <islktt$kt1$1@dont-email.me> <nospam-1E20CE.13382907062011@news.aioe.org> <rqZHp.2350$5v5.528@newsfe11.iad> |
In article <rqZHp.2350$5v5.528@newsfe11.iad>,
Knute Johnson <nospam@knutejohnson.com> wrote:
> On 06/07/2011 10:38 AM, John B. Matthews wrote:
> > I can't find a Sun/Oracle example using invokeAndWait() dated later
> > than 2000, well after the advent of java.util.concurrent. Would it
> > be correct to infer that using, say BlockingQueue, would obviate
> > the need for invokeAndWait()?
>
> There is a happens before relationship in a blocking queue. Putting
> an element in the queue happens before retrieving it from the queue.
> You could synchronize that way as well. All actions before placing
> an element in the queue in one thread would be visible in another
> after removing that element from the queue.
Agreed. In the variation below, a LinkedBlockingQueue would allow one to
schedule a sample on the EDT via invokeLater().
public void startUtilTimer() {
final Queue<Integer> samples = new LinkedBlockingQueue<Integer>();
java.util.Timer sampler = new java.util.Timer();
sampler.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
while (samples.size() > 5) {
samples.remove();
System.out.println(samples);
}
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
samples.add(getValue());
}
});
}
}, 1000, 1000);
}
Compare to the invokeAndWait() variation:
<https://groups.google.com/d/msg/comp.lang.java.gui/sWKy5Oo8s3E/xaGY8-VoMKYJ>
--
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