FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Debian > Debian Java

 
 
LinkBack Thread Tools
 
Old 11-20-2011, 11:52 PM
Keyja Keyja
 
Default Java 613 Threads limit: unable to create new native thread

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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: CACz3JA=m=Km1S6nr7XLwCqpRjWBAAGPdaFe42nafXZW=c5j9p g@mail.gmail.com">http://lists.debian.org/CACz3JA=m=Km1S6nr7XLwCqpRjWBAAGPdaFe42nafXZW=c5j9p g@mail.gmail.com
 
Old 11-21-2011, 11:43 AM
Philipp Hagemeister
 
Default Java 613 Threads limit: unable to create new native thread

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

Keyja Keyja wrote:
> 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 ?
>
>

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

iEYEAREKAAYFAk7KR2EACgkQ9eq1gvr7CFya0QCgmuvhMyqwf0 M3bnxSIaMYCiWq
P+sAnR8eoOQYirEeiV4bQmb4R6GdEIha
=3fyc
-----END PGP SIGNATURE-----


--
To UNSUBSCRIBE, email to debian-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 4ECA4761.2070909@phihag.de">http://lists.debian.org/4ECA4761.2070909@phihag.de
 
Old 11-21-2011, 12:10 PM
Florian Weimer
 
Default Java 613 Threads limit: unable to create new native thread

* Keyja Keyja:

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

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

--
Florian Weimer <fweimer@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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 82wratoc2l.fsf@mid.bfk.de">http://lists.debian.org/82wratoc2l.fsf@mid.bfk.de
 
Old 11-21-2011, 12:21 PM
Keyja Keyja
 
Default Java 613 Threads limit: unable to create new native thread

> 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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: CACz3JAknR9hUns-vihUL-xMXoaCGshyyT58aC7O-L4897QyeAg@mail.gmail.com">http://lists.debian.org/CACz3JAknR9hUns-vihUL-xMXoaCGshyyT58aC7O-L4897QyeAg@mail.gmail.com
 
Old 11-21-2011, 12:23 PM
Keyja Keyja
 
Default Java 613 Threads limit: unable to create new native thread

>
>> 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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: CACz3JAkYa-32PpRkJrc6Qi8U7AYrkw8ASmhHyp74HnkOqYJJ1Q@mail.gmai l.com">http://lists.debian.org/CACz3JAkYa-32PpRkJrc6Qi8U7AYrkw8ASmhHyp74HnkOqYJJ1Q@mail.gmai l.com
 
Old 11-21-2011, 12:33 PM
Florian Weimer
 
Default Java 613 Threads limit: unable to create new native thread

* 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 <fweimer@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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 82sjlhob1l.fsf@mid.bfk.de">http://lists.debian.org/82sjlhob1l.fsf@mid.bfk.de
 
Old 11-21-2011, 12:36 PM
Keyja Keyja
 
Default Java 613 Threads limit: unable to create new native thread

>>>
>>>> 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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: CACz3JAkZSXY3ehVEwUSaCf0cPC6cwJaNB7zUo=+VztsYuHgsD Q@mail.gmail.com">http://lists.debian.org/CACz3JAkZSXY3ehVEwUSaCf0cPC6cwJaNB7zUo=+VztsYuHgsD Q@mail.gmail.com
 
Old 11-21-2011, 12:42 PM
Florian Weimer
 
Default Java 613 Threads limit: unable to create new native thread

* 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 <fweimer@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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 82obw5oamv.fsf@mid.bfk.de">http://lists.debian.org/82obw5oamv.fsf@mid.bfk.de
 
Old 11-21-2011, 12:46 PM
Keyja Keyja
 
Default Java 613 Threads limit: unable to create new native thread

>>> 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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: CACz3JA=7pKmSuFb89fECnr_3zJ58BQEDBOaARjVz0sjnrBDqB Q@mail.gmail.com">http://lists.debian.org/CACz3JA=7pKmSuFb89fECnr_3zJ58BQEDBOaARjVz0sjnrBDqB Q@mail.gmail.com
 
Old 11-21-2011, 03:05 PM
Florian Weimer
 
Default Java 613 Threads limit: unable to create new native thread

* 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 <fweimer@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-java-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 828vn9o3zt.fsf@mid.bfk.de">http://lists.debian.org/828vn9o3zt.fsf@mid.bfk.de
 

Thread Tools




All times are GMT. The time now is 07:33 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org