John.D February 2016

Is there any maximum limit to number of running threads in Linux?

Is there any maximum limit to number of running threads in Linux? Is it possible to count total number of threads from all classes in java?

Answers


TheLostMind February 2016

Technically you should use 2 X numberOfPhysicalCores threads for optimal performance. This post describes the maximum number of threads (Thanks to @gavriel for finding it :P)

Next, to get the number of running threads in the current JVM:

public static void main(String[] args) throws IOException, InterruptedException {
    ExecutorService service = Executors.newFixedThreadPool(4);
    service.execute(new Runnable() {
        public void run() {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    System.out.println(Thread.getAllStackTraces().size());

}

O/P : 5

Post Status

Asked in February 2016
Viewed 2,605 times
Voted 13
Answered 1 times

Search




Leave an answer