Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Java 613 Threads limit: unable to create new native thread

29 views
Skip to first unread message

Keyja Keyja

unread,
Nov 20, 2011, 8:00:01 PM11/20/11
to
Hello,

I am running the following code on my debian server:

public class DieLikeADog {
private static Object s = new Object();
private static int count = 0;
public static void main(String[] argv){
for(;;){
new Thread(new Runnable(){
public void run(){
synchronized(s){
count += 1;
System.err.println("New thread #"+count);
}
for(;;){
try {
Thread.sleep(100);
} catch (Exception e){
System.err.println(e);
}
}
}
}).start();
}
}
}

I got this code here:
http://stackoverflow.com/questions/763579/how-many-threads-can-a-java-vm-support

On my server, the program crashes after 613 threads. This is not
normal, and has to be related to my server configuration. I had the OS
installed when I started to rent the server at http://www.nuxit.com/
and I never messed with the configuration.

Debian version: 5.0.8
Java version: 1.6.0_26

Can anyone help me please ? I was forced to put my website offline
because of this bug. I always have this limit of 613 threads no matter
which program I run on my debian server.

Can anyone help please ?


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/CACz3JA=m=Km1S6nr7XLwCqpRjWBAAGPdaFe42nafXZW=c5j...@mail.gmail.com

Philipp Hagemeister

unread,
Nov 21, 2011, 8:20:02 AM11/21/11
to
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

First of all: What error message do you get? How much memory do you have
in the system? What is the output of uname -a on your system?

On my system, this program easily goes to 10000, although it demands a
lot of memory. You may want to specify a lower stack size, like this:

java -Xss150k DieLikeADog

Also, make sure you have sufficient memory available, basically the
number of threads * memory required for an empty thread. Since each
thread seems to take about 100k, this boils down to at least a GiB for
10k threads. YMMV. Note that on a 32-bit architecture, you will run out
of address space long before running out of actual memory. While you
could do crazy things with fork, I *strongly* recommend you use a 64-bit
architecture.

If you plan on having a quadruple-digits number of threads, I suggest
you either rewrite your code to use threadpools or use really fast
hardware with lots of memory (say, 10GiB)..

- -- Philipp
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)

iEYEAREKAAYFAk7KR2EACgkQ9eq1gvr7CFya0QCgmuvhMyqwf0M3bnxSIaMYCiWq
P+sAnR8eoOQYirEeiV4bQmb4R6GdEIha
=3fyc
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/4ECA4761...@phihag.de

Florian Weimer

unread,
Nov 21, 2011, 8:20:02 AM11/21/11
to
* Keyja Keyja:

> On my server, the program crashes after 613 threads.

Is this on i386? Have you reduced the default stack size?

--
Florian Weimer <fwe...@bfk.de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/82wrato...@mid.bfk.de

Keyja Keyja

unread,
Nov 21, 2011, 8:30:02 AM11/21/11
to
>
>> On my server, the program crashes after 613 threads.
>
> Is this on i386?

Yes.

>Have you reduced the default stack size?

I have tried to. And ulimit says my changes were accounted, but how to
be sure the default stack size is what I said ?


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/CACz3JAkYa-32PpRkJrc6Qi8U...@mail.gmail.com

Keyja Keyja

unread,
Nov 21, 2011, 8:30:03 AM11/21/11
to
> First of all: What error message do you get?

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

>How much memory do you have in the system?

2GB

> What is the output of uname -a on your system?

Linux de801.ispfr.net 2.6.18-028stab085.5 #1 SMP Thu Apr 14 15:06:33
MSD 2011 x86_64 GNU/Linux

> On my system, this program easily goes to 10000, although it demands a
> lot of memory. You may want to specify a lower stack size, like this:
>
> java -Xss150k DieLikeADog
>

It doesn't change anything, whatever i use for Xss, Xmx, or even
ulimit. It doesn't work also if I edit limits.conf

> Also, make sure you have sufficient memory available, basically the
> number of threads * memory required for an empty thread. Since each
> thread seems to take about 100k, this boils down to at least a GiB for
> 10k threads. YMMV. Note that on a 32-bit architecture, you will run out
> of address space long before running out of actual memory. While you
> could do crazy things with fork, I *strongly* recommend you use a 64-bit
> architecture.
>

I'm already using a 64 bit architecture.

> If you plan on having a quadruple-digits number of threads, I suggest
> you either rewrite your code to use threadpools or use really fast
> hardware with lots of memory (say, 10GiB)..
>

I plan on using around 2000 threads and the program will run extremely
fast, i'm sure of that. I just need to get rid of this system
limitation.


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/CACz3JAknR9hUns-vihUL-xMX...@mail.gmail.com

Florian Weimer

unread,
Nov 21, 2011, 8:40:02 AM11/21/11
to
* Keyja Keyja:

>>
>>> On my server, the program crashes after 613 threads.
>>
>> Is this on i386?
>
> Yes.

You should switch to amd64, then such problems will disappear.

>>Have you reduced the default stack size?
>
> I have tried to. And ulimit says my changes were accounted, but how to
> be sure the default stack size is what I said ?

I think you need to pass a suitable -Xss option when you start the JVM.

--
Florian Weimer <fwe...@bfk.de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/82sjlho...@mid.bfk.de

Keyja Keyja

unread,
Nov 21, 2011, 8:40:03 AM11/21/11
to
>>>
>>>> On my server, the program crashes after 613 threads.
>>>
>>> Is this on i386?
>>
>> Yes.
>
> You should switch to amd64, then such problems will disappear.
>

You mean I should rent another dedicated server ? At another company ?
Is that what you mean ?

>>>Have you reduced the default stack size?
>>
>> I have tried to. And ulimit says my changes were accounted, but how to
>> be sure the default stack size is what I said ?
>
> I think you need to pass a suitable -Xss option when you start the JVM.
>

I have done it and it changes nothing.


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/CACz3JAkZSXY3ehVEwUSaCf0cPC6cwJaNB7zUo=+VztsY...@mail.gmail.com

Keyja Keyja

unread,
Nov 21, 2011, 8:50:02 AM11/21/11
to
>>> You should switch to amd64, then such problems will disappear.
>
>> You mean I should rent another dedicated server ? At another company ?
>> Is that what you mean ?
>
> Not necessarily, most servers are 64-bit capable.
>

I'm sorry but I don't understand. My server is already running in a 64
bit architecture.
Maybe i didn't understand your question about i386...

>>> I think you need to pass a suitable -Xss option when you start the JVM.
>
>> I have done it and it changes nothing.
>
> Okay, then you need to provide more details: the exact way how you start
> the JVM, and how the JVM crashes.
>

$> java -Xss128k DieLikeADog

produces a crash after 613 threads

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:640)


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/CACz3JA=7pKmSuFb89fECnr_3zJ58...@mail.gmail.com

Florian Weimer

unread,
Nov 21, 2011, 8:50:02 AM11/21/11
to
* Keyja Keyja:

>> You should switch to amd64, then such problems will disappear.

> You mean I should rent another dedicated server ? At another company ?
> Is that what you mean ?

Not necessarily, most servers are 64-bit capable.

>> I think you need to pass a suitable -Xss option when you start the JVM.

> I have done it and it changes nothing.

Okay, then you need to provide more details: the exact way how you start
the JVM, and how the JVM crashes.

--
Florian Weimer <fwe...@bfk.de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/82obw5o...@mid.bfk.de

Florian Weimer

unread,
Nov 21, 2011, 11:10:03 AM11/21/11
to
* Keyja Keyja:

>>>> You should switch to amd64, then such problems will disappear.
>>
>>> You mean I should rent another dedicated server ? At another company ?
>>> Is that what you mean ?
>>
>> Not necessarily, most servers are 64-bit capable.
>>
>
> I'm sorry but I don't understand. My server is already running in a 64
> bit architecture.

What does "java -version" show?

--
Florian Weimer <fwe...@bfk.de>
BFK edv-consulting GmbH http://www.bfk.de/
Kriegsstraße 100 tel: +49-721-96201-1
D-76133 Karlsruhe fax: +49-721-96201-99


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/828vn9o...@mid.bfk.de

Keyja Keyja

unread,
Nov 21, 2011, 2:20:01 PM11/21/11
to
>> I'm sorry but I don't understand. My server is already running in a 64
>> bit architecture.
>
> What does "java -version" show?
>

de801:~# java -version
java version "1.6.0_26"
Java(TM) SE Runtime Environment (build 1.6.0_26-b03)
Java HotSpot(TM) 64-Bit Server VM (build 20.1-b02, mixed mode)


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/CACz3JAk2qOhGkhnv2wHA8WvNU-Xfk80ZXQMsMq3=4B8zm...@mail.gmail.com

Keyja Keyja

unread,
Nov 22, 2011, 7:40:02 AM11/22/11
to
Thanks to both of you for your help. I have just found the cause of
this and I wanted to let you know.

My issue has nothing to do with computer programming, nor debian, nor
linux. My host provider, nuxit.com, has introduced this limitation
artificially in my system.

Regards.


--
To UNSUBSCRIBE, email to debian-ja...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listm...@lists.debian.org
Archive: http://lists.debian.org/CACz3JAmDTM6U6VsByJCD-VAO...@mail.gmail.com
0 new messages