mvn test java.lang.OutOfMemoryError:无法创建新的本机线程

发布于 2024-11-09 09:15:29 字数 1276 浏览 0 评论 0原文

当我运行 mvn test 时,我收到以下异常。我尝试过提高和降低 Xmx 和 Xss JVM 设置,并突破 ulimit 下的所有限制。大约有 1300 个测试,最后 200 个测试总是失败,但有此例外。单独运行这些测试可以让它们通过。我的 ubuntu 机器上也通过了同样的测试。我在 Mac 上运行测试时收到此异常。我很确定这是一个环境问题,但我已经调整了我所知道的每一个设置,但绝对没有运气。

我使用 mvn 2.1 和 Java 6。我的测试框架是 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)

When I run mvn test I receive the below exception. I have tried both raising and lowering my Xmx and Xss JVM settings and bumping all limits under ulimit. There are about 1300 tests and the last 200 always fail with this exception. Running those tests by themselves allows them to pass. The same tests pass on my ubuntu box. I receive this exception when running the tests on my mac. I am pretty sure its an environment issue, but I have tweaked every setting that I am aware of with absolutely no luck.

I am using mvn 2.1 and Java 6. My test framework 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)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

思慕 2024-11-16 09:15:29

我使用 Maven Surefire 插件 (v2.12) 遇到了这个问题。我必须按如下方式配置 Surefire:

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

如果我在配置中省略了“forkMode”元素,我将收到“无法创建新的本机线程”错误,因为 java Surefire 进程将创建数千个线程,否则超出了我的操作系统限制( Mac OSX——您可以在活动监视器中看到这一点)。

据我所知,所有新线程都会被创建,因为在 Surefire 中默认的“forkMode”是“once”,并且创建的任何新线程都不会消失,直到“one”surefire 进程终止。

最后一点:调整我的 JVM 内存设置似乎没有效果(好或坏)。使用默认值可以正常工作,如下所示:

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

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 config, I would get the "unable to create new native thread" error because the java Surefire process would create thousands of threads otherwise, exceeding my OS limit (Mac OSX -- you can see this in the Activity Monitor).

As best I can tell, all the new threads are getting created because the default "forkMode" is "once" in Surefire, and whatever new threads are getting created don't die off until the "one" surefire process terminates.

One final note: adjusting my JVM memory settings seemed to have no effect (good or bad). Using default values worked normally, as did the following:

<argLine>-Xss512k -Xms512m -Xmx4096m -XX:MaxPermSize=2048m</argLine>
情独悲 2024-11-16 09:15:29

与 sappenin 的答案相关,对于较新版本的 Surefire 插件,您应该使用 forkCount 和 reuseForks 配置参数(而不是已弃用的 forkMode)。生成的插件配置可能类似于所示的代码。

<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>

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

Related to sappenin's answer, you should use the forkCount and reuseForks configuration parameters (instead of deprecated forkMode) for newer versions of the surefire plugin. The resulting plugin configuration might look like the shown code.

<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>

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

∝单色的世界 2024-11-16 09:15:29

您(或代表您行事的人)在测试中创建了太多线程。通过在分叉测试进程运行时运行 jstack 来确认这一点,它几乎肯定会显示大量且不断增加的线程。

尝试限制线程池的大小或确保它们被正确分配。如果 mac 支持类似 ulimit 的功能,您也许可以增加每个进程的最大线程数。在 Windows 上你会失败得更惨。

You (or someone acting on your behalf) is creating too many threads in your tests. Confirm this by running jstack on the forked test process while it runs, it'll almost certainly show a huge and increasing number of threads.

Try limiting the size of your thread pool or make sure they are allocated properly. If the mac supports something like ulimit you might be able to increase the max number of threads per process. You will fail even more miserably on Windows.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文