Detecting java being out of memory