What is the maximum number of threads supported by Java EE?

5

I am analyzing how to rewrite the architecture of a Java program would like to know how many threads the scheduler supports? or how can I infer this amount based on the processing power of my PC / Server / Cluster?

    
asked by anonymous 08.09.2015 / 03:02

2 answers

4

I do not know a problem where a large number of threads can help. You may have thousands of threads on most modern computers and up to tens of thousands on more powerful servers, but this will not help at all depending on the problem you are solving. @Bigown has already talked a little about it.

In addition, a limit still depends on the JVM you are using. In a controlled environment, you can measure and determine a theoretical limit yourself, after all it can always vary depending on the use the machine is having over time.

Create a program that does the following:

  • Instantiate a thread and load the average amount of data you intend to use on each.
  • Recover the amount of memory used and log this value along with the number of threads created so far
  • Repeat steps 1 and 2, always creating new threads and storing values
  • Let the program run for a while, throw the saved values into a worksheet and you will have a ratio of the number of threads to the memory used.

    Note that none of this has to do with performance, because when there are many more threads than CPUs, performance tends to fall due to overhead of scheduling.

    In parallelism work I've done, I had to try the problem with different numbers of threads to determine the optimal amount. But all this still involves details of how the threads communicate and consolidate the end result.

    I suggest that you completely formulate your problem in a new question and ask about its approach, if it is appropriate, rather than questioning a technical detail that is unlikely to be decisive in its implementation.

        
    08.09.2015 / 03:51
    3

    This information is not relevant. The processing architecture and operating system will determine this. There may be a theoretical limit, but what will determine the limit is practicality.

    It is only possible to know how many threads to use testing. Even so, it is not easy to find a balance in many situations. What may be good at one time may not be in another.

    Two threads can be a lot. Thousands may eventually be perfectly bearable.

    In cases where thread is really the solution it is common for the ideal number to be equal to or close to the number of logical processors.

    Producing parallel code correctly and efficiently is not a simple matter. It's very easy to make a mistake when you get out of trivial cases. Make sure you have won and that effort pays off. There are many cases that have been gained by ending the use of thread . To help you out there are some top-level libraries that make it a little easier to take care of some of the complexity.

    You can better understand this question .

        
    08.09.2015 / 03:17