This discussion is archived
4 Replies Latest reply: Oct 6, 2011 4:08 AM by 892086 RSS

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

892086 Newbie
Currently Being Moderated
Hi


I am programming a Java aplication for complex mathematical operations on windows server 2008 R2, it is using many Java theads and in everyone thread I launch a JNI called to a C++ libraries which does the mathematic operations.

I run the program as a Windows´s service and it´s runnig ok but after one day and half running it finish with this message:


Exception in thread "Thread 0" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:597)
at <mypackage>.<myThreadClasWhichCallJNI>.start(Scenario.java:79)
+...+
+...+
+..+


The C++ libraries are from internet and I can not debug or modified them.


My machine is runnig a Windows server 2008 R2 64 bits with 8Gb RAM
The C Libraries are 32 bits
The JVM is a jdk 1.6.0_27 32 bits


Why is this happening?
I´d like to debug the memory but I don´t know it and I don´t find how test the native memory from java

In last option I would program my aplication for obtains the used native memory before launch more threads or C process, but I do not know how


Thanks
  • 1. Re: java.lang.OutOfMemoryError: unable to create new native thread
    DrClap Expert
    Currently Being Moderated
    It's happening because there is a limit on the number of threads you can have active at one time. Despite the name of the exception class, it actually has nothing to do with your memory.
  • 2. Re: java.lang.OutOfMemoryError: unable to create new native thread
    892086 Newbie
    Currently Being Moderated
    Hi

    thanks you for help me


    I have tested the threads´ number and it´s round 500 or 700 in the worst case.


    In more tests, I have changed the JVM options, I have used diferent memory params (Xms, Xmx and Xss) but I have the same problem.


    Maybe I have to use Xmn, XX:PermSize and XX:MaxPermSize but I don´t know what happen when a thread calls native libraries (they are C libraries ) if the JVM loads the libraries everytime (600 threads -> 600 loads) or if it use the same reference for everyone
  • 3. Re: java.lang.OutOfMemoryError: unable to create new native thread
    802889 Explorer
    Currently Being Moderated
    889083 wrote:
    Hi

    thanks you for help me


    I have tested the threads´ number and it´s round 500 or 700 in the worst case.


    In more tests, I have changed the JVM options, I have used diferent memory params (Xms, Xmx and Xss) but I have the same problem.


    Maybe I have to use Xmn, XX:PermSize and XX:MaxPermSize but I don´t know what happen when a thread calls native libraries (they are C libraries ) if the JVM loads the libraries everytime (600 threads -> 600 loads) or if it use the same reference for everyone
    The problem has nothing to do with memory stop looking at memory related JVM settings. The operating system simply doesn't allow you to create more threads. You will simply need to reduce the number of threads created (or make sure they actually finish).
  • 4. Re: java.lang.OutOfMemoryError: unable to create new native thread
    892086 Newbie
    Currently Being Moderated
    Hi

    my operating system is Windows server 2008 64bits because my hardware is 64bits and the C libraries are compiled for Windows. I can´t change the operating system or the libraries.

    My JVM is 32 bits because the C libraries are 32 bits and for using JNI the JVM and the libraries must have the same bits.


    The error is not always with the same number of threads, can you tell me what is my limit or can you tell me how I can look for it? Because the microsoft page tell me a number bigger then one thorusand, very bigger than my number of threads


    I´m sure that I have closed the threads and I remove reference to the closed threads.


    Thanks

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points