How many threads can a Java VM support?

前端 未结 12 1439
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-11-22 06:32

How many threads can a Java VM support? Does this vary by vendor? by operating system? other factors?

12条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-11-22 07:07

    You can process any number of threads; there is no limit. I ran the following code while watching a movie and using NetBeans, and it worked properly/without halting the machine. I think you can keep even more threads than this program does.

    class A extends Thread {
        public void run() {
            System.out.println("**************started***************");
            for(double i = 0.0; i < 500000000000000000.0; i++) {
                System.gc();
                System.out.println(Thread.currentThread().getName());
            }
            System.out.println("************************finished********************************");
        }
    }
    
    public class Manager {
        public static void main(String[] args) {
            for(double j = 0.0; j < 50000000000.0; j++) {
                A a = new A();
                a.start();
            }
        }
    }
    

提交回复
热议问题