Can I catch an out of memory error inside a SwingWorker thread
posted 6 years ago
I'm not sure if this is the right forum for this question. If not, I apologize... but my question is:
I have a java app that uses a SwingWorker to process image information pixel by pixel and covert this information into other object that my app requires. Now, depending on the size of the image, this could be a very long running and memory intensive process so I decided to perform all this stuff inside the doInBackground method of a SwingWorker object. For the most part this works ok. The problem is, if the user starts with a very large image, say 2816 x 2112 pixels (with -Xmx512m vmarg) one of the underlying Java classes throws and OOM. I can understand this and don't have a problem with it but that exception doesn't seem to make it back to my code. I've surrounded my code in the doInBackground method with a try/catch block that specifically looks for an OOM but the catch code is never executed. Can I catch that exception? I'd like to cleanup the newly created objects before exiting the thread. Is it possible to die gracefully?
You've gotta fight it! Don't give in! Read this tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user