-1

We come across the error "java.lang.OutOfMemoryError: Requested array size exceeds VM limit" in the log files and also we observed other process also running after this error

  1. Why the server is not stopped and other process is also running after the above error?
  2. Does all the java.lang.OutOfMemoryError errors will block the entire application or not?
  3. Assume there are 10 threads out of which one thread got failed with OutofMemory error. In such a case will all the threads will be blocked or other 9 threads will continue the process

Example logger message:

example...(QuartzScheduler.java:2166) - Job (DEFAULT.jobLaunchStatusPoller threw an exception. org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.OutOfMemoryError: Requested array size exceeds VM limit] at org.quartz.core.JobRunShell.run(JobRunShell.java:210) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546) Caused by: java.lang.OutOfMemoryError: Requested array size exceeds VM limit [Mar 17 13:32:24] [3578814] WARN [PollingScheduler_Worker-19] (JobExecutor.java:54) - Job Execution Started.

Thanks.

user2323036
  • 1,515
  • 5
  • 19
  • 27
  • Generally, servers try not to crash because of one exception. Google for `setUncaughtExceptionHandler` if you want to understand how they do this. – kdgregory Mar 28 '14 at 13:02

3 Answers3

3

The OutOfMemoryError means that JVM does not have enough space to allocate memory for a new object and the garbage collector can not give additional space. This error is thrown by the instruction causing the memory overflow but does not kill the thread. OutOfMemoryError is a throwable object that you can catch.

You should read some thread about how to configure your heapspace : Increase heap size in Java

Community
  • 1
  • 1
Thomas
  • 1,410
  • 10
  • 24
  • Assume there are 10 threads...One of the thread throws the OutofMemoryError....will the 9 threads will continue the processing or all will be blocked – user2323036 Mar 28 '14 at 12:51
  • But how come i see the process is running in the logs even after this exception occurs – user2323036 Mar 28 '14 at 12:57
  • example...(QuartzScheduler.java:2166) - Job (DEFAULT.jobLaunchStatusPoller threw an exception. org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: java.lang.OutOfMemoryError: Requested array size exceeds VM limit] at org.quartz.core.JobRunShell.run(JobRunShell.java:210) at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:546) Caused by: java.lang.OutOfMemoryError: Requested array size exceeds VM limit [Mar 17 13:32:24] [3578814] WARN [PollingScheduler_Worker-19] (JobExecutor.java:54) - Job Execution Started. – user2323036 Mar 28 '14 at 13:00
0

the -XmX parameter when starting the VM, allows you to change the RAM allocated for the JVM.

java -XmX100G myClass 

However, be generous with the amount of memory yougive it, other processes may need it.

James Parsons
  • 6,097
  • 12
  • 68
  • 108
  • Oh really `100G` ? So huge! Does `G` refers giga? – Keerthivasan Mar 28 '14 at 12:53
  • Yep, Some guy is having problems because he wants more than 300G – James Parsons Mar 28 '14 at 12:56
  • 1
    And because some guy is having trouble you offer a gigabyte amount as an answer here? Bit misleading don't you think, I would give a more realistic example. And you want to opposite of the word generous: conservative. – Gimby Mar 28 '14 at 12:58
0

@Thomas gave nice response, but I dont agree with one thing.

According to Javadoc for Error class, you should never try to catch Error or any Subclass.

Make sure you will never end up here and IF YOU EXPECT ERROR = BAD DESIGN/ALGORITHM

Lukino
  • 1,407
  • 13
  • 14
  • Servers have different design goals than normal applications. – kdgregory Mar 28 '14 at 13:08
  • @kdgregory - I don't understand what you meant but that. If you meant that if you have Server application which runs other application or by application that is running inside another server application ?? So you will catch OutOfMemory error and do what ?? (I can't see some possible use cases, but code that did this once, will do so second time. You could add more memory, but if application is greedy and badly design, you could end up with OutOfMemory error again. – Lukino Mar 28 '14 at 13:10
  • An app-server, such as Tomcat, must not shut down because something bad happened while processing one request. It's the same reason that your operating system doesn't shut down the computer due to a misbehaving program. – kdgregory Mar 28 '14 at 14:11
  • We could go on and on, but: - yes, computer should not shutdown when program is misbehaving, but it should when OS is misbehaving - then it is problem inside OS and potentially bug - same approach to app-server. If request is processed by server and forwarded to application successfully and then error appear, it is App problem. But if there is problem with 1st processing, then it is app-server problem, correct ? – Lukino Mar 28 '14 at 14:58