To create a new class, import the following test code:
1 Public classTestnativeoutofmemoryerror {2 Public Static voidMain (string[] args) {3 4 for(inti = 0;; i++) {5System.out.println ("i =" +i);6 NewThread (NewHoldthread ()). Start ();7 }8 }9 Ten } One A classHoldthreadextendsThread { -Countdownlatch CDL =NewCountdownlatch (1); - the PublicHoldthread () { - This. Setdaemon (true); - } - + Public voidrun () { - Try { + cdl.await (); A}Catch(interruptedexception e) { at } - } -}
Running the results on my development environment is as follows:
1 ...... 2 i = 39353newnative thread4at Java.lang.Thread.start0 (Native Method)5at Java.lang.Thread.start (thread.java:714) 6at Com.study.thinking.in.java.concurrent.TestNativeOutOfMemoryError.main ( TESTNATIVEOUTOFMEMORYERROR.JAVA:15)
The results of each run are not exactly the same, but the big difference is not bad.
Several parameters that affect the result:
1. Physical memory using 64-bit OS can allocate larger memory to virtual machines
2. Jvmmemory reduce this parameter can increase the number of concurrent threads, non-multiple relationships -xms1024m-xmx1024m can not be more than-xms512m-xmx512m one-fold thread
3. Threadstacksize reduces the stack size of a single thread, in the valid range, is a multiple relationship
More Information reference: http://sesame.iteye.com/blog/622670
How many threads are concurrently started by the Java virtual function