java - 非特权用户的 Maven 内存不足

标签 java maven ubuntu centos out-of-memory

在 CentOS 机器上运行我们的 maven 测试时,我遇到了奇怪的 maven 问题。问题是,当我运行时

mvn install

作为非特权用户,它永远挂起并出现以下异常

java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:713)
at org.apache.maven.surefire.booter.ForkedBooter.launchLastDitchDaemonShutdownThread(ForkedBooter.java:181)
at org.apache.maven.surefire.booter.ForkedBooter.exit(ForkedBooter.java:141)
at org.apache.maven.surefire.booter.ForkedBooter.exit(ForkedBooter.java:141)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:125)

Exception in thread "main" Exception in thread "main" java.lang.OutOfMemoryError: unable to create new native threadjava.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:713)
at org.apache.maven.surefire.booter.ForkedBooter.launchLastDitchDaemonShutdownThread(ForkedBooter.java:181) at org.apache.maven.surefire.booter.ForkedBooter.launchLastDitchDaemonShutdownThread(ForkedBooter.java:181)
at org.apache.maven.surefire.booter.ForkedBooter.exit(ForkedBooter.java:141)
at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:133)

Exception in thread "metrics-meter-tick-thread-1" java.lang.OutOfMemoryError: unable to create new native thread
at java.lang.Thread.start0(Native Method)
at java.lang.Thread.start(Thread.java:713)
at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:949)
at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1017)  at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:949)
at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1017)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1163)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
at java.lang.Thread.run(Thread.java:744)

但是,如果我以 root 身份运行 mvn,则没有问题。 此外,在 Ubuntu 机器上作为非特权用户,测试运行良好。

我的堆栈:

  • Maven 出现在 3.0.5 和 3.1.1 上
  • CentOS 6.5 内核 2.6.32-431.3.1.el6.x86_64
  • Ubuntu 13.10 内核 3.11.0-15-generic
  • JDK 1.7.0_51(在 ubuntu 和 CentOS 上)

一切都很普通。

其他事实:

  • $MAVEN_OPTS 未在任何 shell(CentOS 或 Ubuntu)中设置。我确实尝试了 MAVEN_OPTS="-Xms256m -Xmx4096m -XX:MaxPermSize=256m -Dmaven.surefire.debug=-Xmx3000m"的组合,但结果相同
  • $JAVA_OPTS 也没有在任何 shell 中设置。我尝试了与上述类似的选项,但由于它没有效果,所以我放弃了它。
  • 尝试为每个用户设置 ~/.m2 目录中的 surefire 插件参数,但没有任何结果,所以我放弃了配置。
  • 从 pstree 中,我看到 maven 的 java 在所有情况下都创建了约 1060 个进程的分支。

谁能解释一下这是怎么回事。

非常感谢

最佳答案

java.lang.OutOfMemoryError: 无法创建新的 native 线程

这是重要的部分。 OutOfMemoryError 已扩展为表示“无法分配一些基本资源”。在这种情况下,新线程,而不是内存。

可能的解释:对于普通用户,您对线程数的“ulimit”比对于 root 用户要小。当您转到新的 Linux 时,它对普通用户有更大的最大值。

我发现这个问题是因为“metrics-meter-tick-thread-1”线程让我很伤心——一个 (Cassandra) 库一遍又一遍地创建这些线程,我有 300 个名为“metrics-meter-”的线程tick-thread-1”和“metrics-meter-tick-thread-2”。

关于java - 非特权用户的 Maven 内存不足,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21430906/

相关文章:

ubuntu - 将 p4 diff 更改为 diff 在 ubuntu 中不起作用

java - 在 spring-jdbc 中使用 "where in"

java - Android 1.5 中的 String[].clear

java - SNAPSHOT 和 RELEASE 版本未在 Maven 本地存储库中获得更新

java - 测试组装 jar 的行为

linux - 通过 Sublime text 保存在 Ubuntu 终端上完成的工作

ubuntu - Jenkins 无法配置?

java - 小程序在网络上的连接

java - @Embedded 对象如果没有基本数据类型字段则不会自动实例化

java - 使用 REST API 时出现内部服务器错误