The moose likes Threads and Synchronization and the fly likes unable to create new native thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Threads and Synchronization
Bookmark "unable to create new native thread" Watch "unable to create new native thread" New topic

unable to create new native thread

Karthik Anant

Joined: Nov 02, 2009
Posts: 20
Hi all,
Am trying to spawn a new thread for every client that is connecting to my application. At present am not able to spawn more than 1085 threads, beyond which am getting the below exception. I am using HP UX 11.31 64 bit machine

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 poc.MultipleThreadSpawning.main(MultipleThreadSpawning.java:15)

Would greatly appreciate any insights to overcome this problem.

Thanks in advance
Edward Harned
Ranch Hand

Joined: Sep 19, 2005
Posts: 291

Did you look up the description for: java.lang.OutOfMemoryError
Did you understand it?
Did you increase the memory for the JVM with switches? (-Xm...)

Using thousands of threads is usually a sign of bad design. Try reading about RMI and how it uses/reuses threads for each client call.

Ed's latest article: A Java Parallel Calamity http://coopsoft.com/ar/Calamity2Article.html
Karthik Anant

Joined: Nov 02, 2009
Posts: 20
Thanks for the reply

yes, apart from increasing the -Xmx i've tried giving a lower value for it as well to make more memory available for native kernel.

i just said clients to indicate that its not a bad design and i cannot do away with the thousand threads running. I use TCP and hence i manage the socket output stream in a thread for each client connection. So nothing to do with RMI here.

The issue is more related to the HP UX 11.3 machine, as the same program runs fine in other OS such as AIX.
Karthik Anant

Joined: Nov 02, 2009
Posts: 20
hi all,
the problem got resolved soon after running the program in 64 bit mode.
I agree. Here's the link: http://aspose.com/file-tools
subject: unable to create new native thread
Similar Threads
OutOfMemory-unable to create native thread
Making a database connection inside a thread
Thread.start() or thread.stop()
Max number of threads in a JVM
Somany Timer Threads are creating in Jboss 4.2.