Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space
I'm developing an applet to show panoramas. Sometimes they can be larger than the memory allocated to the JVM on the client machine. In order to develop code to handle an OutOfMemoryError gracefully, I have restricted the memory allocated to the JVM while testing my applet in Eclipse (it's not an Eclipse problem).
While trying to load an image in the memory restricted JVM, I get an OutOfMemoryError from:
class sun.awt.image.ImageFetcher extends java.lang.Thread
Here is the stack trace:
* PanCyl2 [Java Applet]
sun.applet.AppletViewer at localhost:1946
Thread [Java2D Disposer] (Running)
Thread [AWT-Shutdown] (Running)
Thread [AWT-Windows] (Running)
Thread [AWT-EventQueue-0] (Running)
Thread [thread applet-pancyl.PanCylApplet.class] (Running)
Thread [DestroyJavaVM] (Running)
Thread [AWT-EventQueue-1] (Running)
Thread [Image Fetcher 0] (Suspended (exception OutOfMemoryError))
ImageFetcher.run() line: 149 [local variables unavailable]
Thread [Thread-3] (Running)
D:\jdk1.5\bin\javaw.exe (Jul 17, 2007 10:30:26 AM)
Here is the method in my applet where the OOME happens:
private boolean getImageParametersAndPixels()
width = image.getWidth(canvas);
height = image.getHeight(canvas);
pixels = new int [width * height ];
pg = new PixelGrabber(image,0,0,width,height,true);
HAPPENS HERE->while (pg.grabPixels(100l) != true);
pixelObject = pg.getPixels();
// catch (Throwable oome)
// System.err.println("Throwable: getImageParametersAndPixels()...");
// return false;
catch (OutOfMemoryError oome)
pixels = (int )pixelObject;
PixelGrabber grabPixels() is supposed to throw an InterruptedException if --
/* @param ms the number of milliseconds to wait for the image pixels
* to arrive before timing out
* @return true if the pixels were successfully grabbed, false on
* abort, error or timeout
* @exception InterruptedException
* Another thread has interrupted this thread.
But no InterruptedException is thrown. The OOME is raised in ImageFetcher.run() line 149 and my thread that is trying to grabPixels() is suspended. The applet is still alive and I could recover if I could detect the OOME.
But there is no way to detect that the OOME has occured.
QUESTION: does anyone have an idea of how to handle this situation?
Shouldn't ImageFetcher.run() throw something? Like an OutOfMemoryError or something so that grabPixels() can throw an InterruptedException like the documentation says it will???
To unsubscribe, send email to firstname.lastname@example.org and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
email@example.com and include in the body of the message "help".