Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #4575

Re: Synchronization when collecting data from the EDT?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!aioe.org!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail
From markspace <-@.>
Newsgroups comp.lang.java.gui
Subject Re: Synchronization when collecting data from the EDT?
Date Sun, 05 Jun 2011 17:46:25 -0700
Organization A noiseless patient Spider
Lines 39
Message-ID <ish813$mnv$1@dont-email.me> (permalink)
References <MdAGp.362$SG4.2@newsfe03.iad>
Mime-Version 1.0
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Injection-Date Mon, 6 Jun 2011 00:46:28 +0000 (UTC)
Injection-Info mx04.eternal-september.org; posting-host="WHnGjYnTz8ERvledrF5DxA"; logging-data="23295"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+m2aPKCY8TPA+0hON+GdVCVwBZg65/RYc="
User-Agent Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.17) Gecko/20110414 Thunderbird/3.1.10
In-Reply-To <MdAGp.362$SG4.2@newsfe03.iad>
Cancel-Lock sha1:EIUi29B4/khJ4BX2bdERQlXxpC8=
Xref x330-a1.tempe.blueboxinc.net comp.lang.java.gui:4575

Show key headers only | View raw


On 6/4/2011 5:38 PM, Knute Johnson 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,

Yes and no.

You are correct, SwingUtilities.invokeLater() does NOT specify that it 
creates a happens-before relationship.  I've griped about this before on 
this group.  I think it should, because it's almost impossible to use 
correctly if it does not.

However, if you look at the implementation, you can see it uses an 
Executor to hand off your runnable to the EDT.  And the Executor method 
invoked does, in fact, specify a happens before relationship.  And I 
can't think of any way to hand off one object (the runnable) to another 
thread with out creating a happens-before relationship.  So as a 
practical matter, I think you must be ok if you don't synchronize yourself.

If feel you must synchronzie (and I don't disagree), the easiest way 
might be to just create a volatile field in the Runnable and let that 
synchronize for you.

   class MyRunnable implements Runnable {
      public volatile int synch;
      public void run() {
        synch++;  // read  synch
        // do stuff here...

      }
    }
...
   MyRunnable run = new MyRunnable();
   run.synch = 42;
   SwingUtilities.invokeLater( run );
...

This is the best I think I can do.

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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