Can anyone tell how we can decide what the maximum threads will be, which we should use to improve performance - this is definitely not the maximum number of threads.
For best performance, the number of threads should be equal to the number of processor cores (do not forget to use -XmsYYYYM and -XmxYYYYM , without them you may encounter a situation where your processor does not assign threads to the cores.)
About maximum flows, your answer was correct, it depends on the hardware and OS. In linux, you can check:
cat /proc/sys/kernel/threads-max
edited.
You can create a thread pool with Integer.MAX_VALUE
But you have limited the amount of maximum use of threads. On my laptop. The command "cat / proc / sys / kernel / threads-max" shows me 126987 .
The code I ran:
package com.stackoverflow.test; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; public class TestMaxAmountOfThreads { public static void main(String[] args) { ExecutorService serivce = Executors.newFixedThreadPool(Integer.MAX_VALUE); for (int i = 0; i < Integer.MAX_VALUE; i++) { serivce.submit(new Runnable() { public void run() { try { Thread.sleep(Integer.MAX_VALUE); } catch (InterruptedException e) { } } }); System.out.println(i); } } }
Output:
31850
Exception in thread "main" java.lang.OutOfMemoryError: cannot create a new native thread in java.lang.Thread.start0 (Native Method) in java.lang.Thread.start (Thread.java:714) in java.util.concurrent .ThreadPoolExecutor.addWorker (ThreadPoolExecutor.java:949) in java.util.concurrent.ThreadPoolExecutor.execute (ThreadPoolExecutor.java:1360) in java.util.concurrent.AbstractExecutorService.submit (AbstractExecutorService.java test.TestMaxAmountOfThreads.main (TestMaxAmountOfThreads.java:10)
Therefore, I can only use 31850 tags, without configuring jvm.
Maxym
source share