One of my tasks is eating up too much memory and failing with an OutOfMemoryError exception. Can I catch that exception? Can I get a warning when I'm about to run out of memory?
Asked
Active
Viewed 165 times
2
-
I haven't had to look into them personally; but you might want to look into backend instances. They have access to more memory than the default front ends. This is of course assuming there aren't some obvious changes you could implement to conserve memory. http://code.google.com/appengine/docs/java/backends/overview.html – Dave Jan 02 '12 at 16:38
-
Possible duplicate of [Catching java.lang.OutOfMemoryError?](http://stackoverflow.com/questions/2679330/catching-java-lang-outofmemoryerror) – Raedwald Nov 20 '15 at 09:30
1 Answers
2
You can catch the OutOfMemoryError. However, its not recommended.
There are a bunch of reasons why the error occurs, the most obvious one being http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/OutOfMemoryError.html. You also have reasons like 98% of GC time is spent in reducing less than 2% of Heap etc.
As for a call back before OutOfMemoryError, there is no such thing.

Pavan
- 1,245
- 7
- 10
-
I just want to catch it so I can log it and tell AppEngine to give up. AppEngine restarts any tasks that fail for any reason, so when a task throws OutOfMemoryError it just gets restarted, runs out of memory again, and ends up costing lots of money. Do you think that falls under a "recommended" catch of the exception? – Riley Lark Jan 02 '12 at 16:38
-
Oh then you can do it. Like I said, you can definitely catch it. Go ahead and add a catch (OutOfMemoryError e). You can even catch a Throwable if there are other such things which might cost you. However, remember that once you catch it, if you do not stop your app engine, the control continues since it is like any other exception catch. – Pavan Jan 02 '12 at 16:40