3

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)
6
  • Are you catching/logging Exception somewhere? Commented Dec 15, 2012 at 12:14
  • 6
    Uncaught Exceptions only terminate their own thread, not the entire application. Commented Dec 15, 2012 at 12:15
  • Could you paste the part of your code when you create the new thread ? Commented Dec 15, 2012 at 12:16
  • I have a catch (Exception e) around this throwing code -- however this exception descends from java.lang.Error so the answer is No. Commented Dec 15, 2012 at 12:17
  • @JanDvorak, good point. However my app then stalls -- the main thread. Commented Dec 15, 2012 at 12:21

2 Answers 2

5
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.

Sign up to request clarification or add additional context in comments.

4 Comments

No, that's not the reason why the process is not stopping. The reason is the one Jan Dvorak gives in his comment to the OP.
Wouldn't Uncaught Exceptions on the main thread terminate the process.?
@AjayGeorge Only if all the other threads are daemon threads.
@FrankPavageau correct. Updating my answer to add that clarity.
2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.