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


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

Re: Worker Threads and ED

From "Larry A Barowski" <larry.a.barowski@THRWHITE.remove-dii-this>
Subject Re: Worker Threads and ED
Message-ID <sfidneAZUrwogT3VnZ2dnUVZ_tTinZ2d@comcast.com> (permalink)
Newsgroups comp.lang.java.gui
References <aVJkk.50144$nD.30868@pd7urf1no>
Date 2011-04-27 15:47 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui

<i.dont.need@any.more.email> wrote in message 
news:aVJkk.50144$nD.30868@pd7urf1no...
>
> ... Is there any way I could instrument the code so that in development, I 
> could throw an exception any time a component is touched by a thread other 
> than the EDT?

I had this need and ended up using AspectJ to
inject a test before every gui call, using the
following aspect:

aspect ThreadChecker {
   pointcut guiCall():
        (call(* java.awt..*(..)) || call(* javax.swing..*(..))
        || call(java.awt..*.new(..)) || call(javax.swing..*.new(..)))
        && !call(* clone()) && !call(void 
SwingUtilities.invokeLater(Runnable))
        && !call(boolean SwingUtilities.isEventDispatchThread())
        && !call(* javax.swing.text.html.HTMLDocument..*(..));

   before(): guiCall() && !within(ThreadChecker) {
      if (!SwingUtilities.isEventDispatchThread()) {
         System.err.println("Bad gui call:");
         System.err.println(thisJoinPoint.getSourceLocation());
         System.err.println(thisJoinPoint.getSignature());
         System.err.println();
      }
   }
}

You'll probably need some tinkering depending on the
Java version you target and which other thread-safe
gui methods you call (repaint() isn't in the above for
example, but I never call it from outside the EDT and
don't expect to ever need to do so).

It's pretty easy to set up a build to inject that test into
a jar file and merge in the ThreadChecker class and
the AspectJ runtime classes.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

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


Thread

Worker Threads and EDT "i.dont.need" <i.dont.need@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
  Re: Worker Threads and ED "tar" <tar@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
    Re: Worker Threads and ED "i.dont.need" <i.dont.need@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
    Re: Worker Threads and ED "Roedy Green" <roedy.green@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
      Re: Worker Threads and ED "jlp" <jlp@THRWHITE.remove-dii-this> - 2011-04-27 15:48 +0000
  Re: Worker Threads and ED "Larry A Barowski" <larry.a.barowski@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
    Re: Worker Threads and ED "i.dont.need" <i.dont.need@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000
      Re: Worker Threads and ED "Larry A Barowski" <larry.a.barowski@THRWHITE.remove-dii-this> - 2011-04-27 15:47 +0000

csiph-web