RE: VisAD threading problems [potential sol'n]

  • To: "Bill Hibbard" <billh@xxxxxxxxxxxxx>
  • Subject: RE: VisAD threading problems [potential sol'n]
  • From: "Ian Graham" <ian@xxxxxxxxxx>
  • Date: Mon, 23 Jun 2003 18:05:24 -0600
Forgot to attach the file, so here it is.

> -----Original Message-----
> From: owner-visad-list@xxxxxxxxxxxxx
> [mailto:owner-visad-list@xxxxxxxxxxxxx]On Behalf Of Ian Graham
> Sent: Monday, June 23, 2003 5:28 PM
> To: Bill Hibbard
> Cc: VisAD List
> Subject: RE: VisAD threading problems [potential sol'n]
>
>
> Hello Bill,
>
> I have a quick fix that seems to resolve my problems.  It needs a closer
> look from someone who knows VisAD better, because I don't really
> understand
> the reason for the conditions that are checked in the code I've removed.
> Basically I've just commented out code that was explicitly
> rerendering, and
> replaced it with a simple repaint() call.
>
> The fix doesn't seem to interfere with any of the mouse controls,
> auto-aspect or animation.  It dramatically improves responsiveness when
> zooming, it gets rid of the multiple rendering I get when I'm using
> auto-aspect, it fixes the display corruption that occurs when using VisAD
> canvases in a JTabbedPane, and so far my I haven't seen a recurrence of
> incomplete display update when I close my dialog that replots with a new
> data reference.
>
> I hope this is the answer!
>
> I would, however, consider tidying up a bit more:  it's really alarming to
> see a Swing component that implements Runnable, given that Swing is
> single-threaded, so at the very least I would instead create an
> inner class
> to implement the rendering thread(even anonymously would be fine
> if you name
> clearly enough the variable you assign it to).
>
> I'm still startled by the dramatic improvement to the feel of my app, for
> which plot changes used to be flickery even when they did finish
> correctly.
>
> Ian
>
//
// VisADCanvasJ2D.java
//

  public void run() {
    Thread me = Thread.currentThread();
    while (renderThread == me) {
      timeout = false;
//      if (component != null) {
//        Graphics g = getGraphics();
//        if (g != null) {
//          paintComponent(g);
//          g.dispose();
//        }
//      }
//      else {
//        paintComponent(null);
//      }
      repaint();

      try {
        synchronized (this) {
          if (!wakeup) {
            if (timeout) {
              wait(1000);
            }
            else {
              wait();
            }
          }
        }
      }
      catch(InterruptedException e) {
        // note notify generates a normal return from wait rather
        // than an Exception - control doesn't normally come here
      }
      synchronized (this) {
        wakeup = false;
      }
    }
  }