• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

JVM's maximum number of Threads?

 
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can i configure JVM's maximum number of Threads?
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to increase or make maximum no of threads that a JVM runs on a single instance.

If so then:

The short answer is that it's limited by how much virtual
address(VA) space you have, both address size (32/64) and swap.

The primary consumers of VA space are the java heap and
associated C heap data structures, and thread stacks and
(fairly small) per-thread C data structrure. A small amount of java heap space is consumed by Thread instances.

The default thread stack size is 512kb for the 32-bit jvm
and 1mb for the 64-bit jvm on solaris sparc. You can gain more VA
space for thread stacks by making the java heap smaller.

java -Xms2g -Xmx2g MAXTHREADS

On 32-bit sparc, you can typically get up to 4k or so threads
before you run out of VA (maximum user VA is ~3.8gb). On
64-bit systems, the amount of swap is the effective limit:
I know of an experiment that successfully created 160k threads.

HTH
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course you're likely to run into severe performance problems long before you reach those levels as the thread administration code (so the code that governs which thread gets to run and for how long) starts to take up so much time that the actual application threads never get any time anymore.
 
Arjun K
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeroen is absolutely right.

The limitations are generally based on system resources -
physical memory and CPU.

The number of threads that can run within a JVM process is generally
limited by the address space for that process. Each thread requires
a thread stack. The more threads you have, the more process address
space you use. The more address space you use for thread stacks, the
less you have for the Java heap. There is one more tricky you have when you have less heap; it triggers more GC occurance. This effects performance largely. So there's a bit of a balance that needs to be achieved. Generally, if you have a lot of active threads you will probably want a lot of heap space as well.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the default maximum Thread capacity of JVM irrespective of physical memory and CPU ?
 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Maybe you should ask yourself why you need so many threads that this becomes an issue for you. Why can't you use a thread pool?
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no default maximum. How manny threads you can create in a given heap size is OS-dependent; as people are trying to tell you, it depends on system resources. Many JVMs nowadays simply use the underlying OS's thread implementation, one Java thread per OS thread. Whatever limits the OS gives you, that's what you get.
 
kri shan
Ranch Hand
Posts: 1491
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JVM supports maximum how many Thread pools? any limit is there?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there is a limit. After all there's a limit to the number of objects you can have in memory at any time.
But you're likely to run into problems because of the available memory or CPU cycles in your computer before you run out of object space...
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic