Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange java.lang.OutOfMemoryError -- process does not crash

I'm seeing a strange java.lang.OutOfMemoryError error (partial stack trace below). The thing is that the java process does not crash. I see this error in the logs but the process seems to stall but does not exit.

Thanks.

Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:691)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:943)
at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1325)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:132)
at com.amazonaws.services.s3.transfer.internal.UploadMonitor.<init>(UploadMonitor.java:126)
at com.amazonaws.services.s3.transfer.TransferManager.upload(TransferManager.java:384)
at com.amazonaws.services.s3.transfer.TransferManager.upload(TransferManager.java:344)
at com.amazonaws.services.s3.transfer.TransferManager.upload(TransferManager.java:272)
like image 331
user1172468 Avatar asked Mar 28 '26 05:03

user1172468


2 Answers

java.lang.OutOfMemoryError: unable to create new native thread   

This is due to the fact that no more native threads could be created from your app.

  1. Check the number of Threads your app is spawning. Most likely this is the culprit.
    You can take a Thread dump for analyzing this.

  2. Then check your stack size. Xss param will give you that. Try tweaking it.

Increasing Xmx won't help you here. In fact on 32 bit JVMs it will exacerbate the issue.

The reason why your process is not stopping is because of the fact that Uncaught Exceptions only terminate their own thread, not the entire application as mentioned by Jan in the comments.

like image 86
Ajay George Avatar answered Mar 29 '26 18:03

Ajay George


An OutOfMemoryError, or any Error for that matter, does not make the JVM crash. It might make it exit if you only have one Thread where you don't catch Errors (not very useful anyway), for example. If the JVM doesn't exit, it will be in a unstable state anyway, and should be restarted.

like image 24
Frank Pavageau Avatar answered Mar 29 '26 19:03

Frank Pavageau