Mvn test java.lang.OutOfMemoryError: cannot create new native thread

When I run mvn test , I get the following exception. I tried to both raise and lower the Xmx and Xss JVM settings and attack all the restrictions under ulimit. There are about 1300 tests, and the last 200 always fail with this exception. Performing these tests alone allows them to pass. The same tests pass in my ubuntu box. I get this exception when running tests on my mac. I am sure that this is a problem with the environment, but I configured all the settings that I know about, completely out of luck.

I am using mvn 2.1 and Java 6. My test environment is junit 4.8.

 java.lang.OutOfMemoryError: unable to create new native thread at java.lang.Thread.start0(Native Method) at java.lang.Thread.start(Thread.java:658) at java.util.concurrent.ThreadPoolExecutor.addIfUnderMaximumPoolSize(ThreadPoolExecutor.java:727) at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:657) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:92) at com.google.appengine.tools.development.ApiProxyLocalImpl$PrivilegedApiAction.run(ApiProxyLocalImpl.java:197) at com.google.appengine.tools.development.ApiProxyLocalImpl$PrivilegedApiAction.run(ApiProxyLocalImpl.java:184) at java.security.AccessController.doPrivileged(Native Method) at com.google.appengine.tools.development.ApiProxyLocalImpl.doAsyncCall(ApiProxyLocalImpl.java:172) at com.google.appengine.tools.development.ApiProxyLocalImpl.makeAsyncCall(ApiProxyLocalImpl.java:138) 
+4
source share
3 answers

I ran into this problem using the Maven Surefire plugin (v2.12). I had to configure surefire as follows:

 <configuration> <forkMode>always</forkMode> ... other surefire config ... </configuration> 

If I omitted the forkMode element in my configuration, I would get the error “it is impossible to create a new native thread”, because the java Surefire process would create thousands of threads otherwise, exceeding the limit of my OS (Mac OSX - you can see this in Monitor activity).

As far as I can tell, all new threads are created because the default forkMode is “once” in Surefire, and no matter what new threads are created, do not die until the “one” completed process is complete.

One final note: tuning my JVM memory seemed to have no effect (good or bad). Using standard values ​​worked fine, as did the following:

 <argLine>-Xss512k -Xms512m -Xmx4096m -XX:MaxPermSize=2048m</argLine> 
+3
source

You (or someone acting on your behalf) create too many threads in your tests. Confirm this by running jstack during the forked test process during its launch, it will almost certainly show a huge and increasing number of threads.

Try to limit the size of the thread pool or make sure that they are correctly distributed. If your Mac supports something like ulimit, you can increase the maximum number of threads for each process. You will lose even more dull in Windows.

+2
source

In response to sappenin's answer, you should use the forkCount and reuseForks configuration options (instead of the obsolete forkMode) for newer versions of the surefire plugin. The resulting plugin configuration may look like the code shown.

 <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.16</version> <configuration> <forkCount>1</forkCount> <reuseForks>false</reuseForks> <argLine>-Xms256m -Xmx1024m</argLine> </configuration> </plugin> </plugins> </build> 

link: http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html

+2
source

All Articles