Re: exception cannot call getImage() from Thread: AWT-EventQueue-1

  • To: ncubukcu@xxxxxxxxx
  • Subject: Re: exception cannot call getImage() from Thread: AWT-EventQueue-1
  • From: Curtis Rueden <ctrueden@xxxxxxxx>
  • Date: Mon, 01 May 2006 12:49:46 -0500
Hi Nihat,

There are restrictions on calling DisplayImpl.getImage from the AWT event thread, because doing so generally results in thread deadlock. Instead, try calling getImage from a completely separate thread. E.g.:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
   new Thread() {
       public void run() {
           com.app.lt.CreateImage imagePr = new com.app.lt.CreateImage();
           try {
               BufferedImage myImage =imagePr.plotImage();
           } catch (RemoteException ex) {
               ex.printStackTrace();
           } catch (VisADException ex) {
               ex.printStackTrace();
           }
       }
   }.start();
   ...
}

Also, I'm not certain what com.app.lt.CreateImage.plotImage does, but from its name, it sounds like it builds or updates a display with DataReferenceImpl.setData and such -- is there a reason such a method would need to call getImage? If you can avoid the getImage call, you can continue using the AWT event thread, if you wish.

-Curtis

ncubukcu wrote:

Hi
I am pretty new to visad and currently exploring its usage for my applications. So far I was able to write some simple applications.

I have run into a problem when I tried to call a visad application through and applet's "submit" button on a web site as in the following format:

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { Util.invoke(false,false, new Runnable() {
           public void run() {
           com.app.lt.CreateImage imagePr = new com.app.lt.CreateImage();
               try {
                   BufferedImage myImage =imagePr.plotImage();
               } catch (RemoteException ex) {
                   ex.printStackTrace();
               } catch (VisADException ex) {
                   ex.printStackTrace();
               }
           }
       });
.
.

the exception I get is;

Exception in thread "AWT-EventQueue-1" visad.VisADError: cannot call getImage() from Thread: AWT-EventQueue-1
       at visad.DisplayImpl.getImage(DisplayImpl.java:2630)
       at visad.DisplayImpl.getImage(DisplayImpl.java:2614)
       at com.app.lt.CreateImage.plotImage(CreateImage.java:94)

where line 94 has the following code;
return display.getImage();

and display object is;
DisplayImplJ2D display = new DisplayImplJ2D(" ", 700, 500);

I looked through old e.mails and it seems like this works for everybody else. It works fine if I run the application by itself. Like I said I am a new user and there maybe much easier way to do this but I just don't know yet. any help is greatly appreciated... thanks in advance..
nihat


==============================================================================
To unsubscribe visad, visit:
http://www.unidata.ucar.edu/mailing-list-delete-form.html
==============================================================================


  • 2006 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: