Hello,
This error has been a nightmare for me. I am not able to deploy my server yet.
After 2 days, it gives up accepting new connections and then dies. The error that I get is a common error
java.lang.OutOfMemoryError: unable to create new native
I did my home work . My ulimits are
core file size (blocks, -c) 1000000
data seg size (kbytes, -d) unlimited
file size (blocks, -f) unlimited
max locked memory (kbytes, -l) unlimited
max memory size (kbytes, -m) unlimited
open files (-n) 4096
pipe size (512 bytes, -p) 8
stack size (kbytes, -s) 8192 >> changed it to 1024 too

cpu time (seconds, -t) unlimited
max user processes (-u) 14335
virtual memory (kbytes, -v) unlimited
My test program stops after 600 threads
Starting Thread: 600
Starting Thread: 601
Starting Thread: 602
Starting Thread: 603
Starting Thread: 604
Starting Thread: 605
Starting Thread: 606
Starting Thread: 607
Starting Thread: 608
Starting Thread: 609
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:574)
at Test.startThreads(Test.java:17)
at Test.main(Test.java:29)
public static void startThreads(){
class TestThread extends Thread {
public void run(){
try{
while(true) sleep(1000);
}catch(Exception e){}
}
}
for(int i = 0;i<10000;i++){
try{
System.out.println("Starting Thread: " + i);
(new TestThread()).start();}
catch(Exception e)
{
e.printStackTrace();
e.getMessage();
System.exit(1);
}
}
}
I was actually able to run this command on my 1GB server and still get the same error.
java -Xms1000m -Xmx1000M Test
Running again gave me 400 threads only.
Here is the free memory at the time I ran this command.
free
total used free shared buffers cached
Mem: 1031644 989132 42512 0 186828 422104
-/+ buffers/cache: 380200 651444
Swap: 2040244 94472 1945772
java version "1.5.0_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_01-b08)
Java HotSpot(TM) Client VM (build 1.5.0_01-b08, mixed mode, sharing)
With the new 1.5
/usr/local/java/jdk1.5.0_02/bin/java -version
java version "1.5.0_02"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-b09)
Java HotSpot(TM) Client VM (build 1.5.0_02-b09, mixed mode)
it gives 879 threads - a little better but still cannot reach more.
uname -a
javaserver.*.com 2.4.27 #2 SMP Tue Aug 10 16:40:59 CDT 2004 i686 i686 i386 GNU/Linux
ls -l /lib/libc.so.*
lrwxrwxrwx 1 root root 13 Aug 10 2004 /lib/libc.so.6 -> libc-2.3.2.so*
Can it be my glibc? Will other JVMs do any good?
In c using the famous pthread_create, it goes till 1532 threads and stops after that.
How can I get this to create [lot] more threads?
Thanks