内存不足是否可能导致 NoSuchMethodError?

Is it possible that lack of memory will cause a NoSuchMethodError?

最近我向 Heroku 部署了一个 Java 应用程序。我部署的应用程序还有一个可以打开的后台进程。该应用程序往往会占用 Heroku 为单个 dyno 分配的所有 512MB - 没有后台进程 运行。在没有打开后台进程的情况下,一切似乎都运行良好,但是当我打开后台进程时,我的应用程序开始使用比分配的 512MB 更多的内存,我立即遇到了 NoSuchMethodErrors。我在下面包含了堆栈跟踪。由于内存不足而抛出 NoSuchMethodError 对我来说似乎很奇怪,但它是我能想到的唯一变量。在我打开后台进程之前,程序运行良好。

真正奇怪的是,一旦我重新启动应用程序,所有端点都将在 JSON 短时间内毫无问题地服务 - 但在一段可变的时间后,相同的端点将开始抛出 NoSuchMethodErrors。应用程序如何找到一个方法,然后 10 分钟后就找不到了?

java.lang.NoSuchMethodError: org.jboss.resteasy.specimpl.BuiltResponse.getHeaders()Ljavax/ws/rs/core/MultivaluedMap;
2015-01-31T01:06:37.924505+00:00 app[web.1]:    at org.jboss.resteasy.core.ServerResponseWriter.setDefaultContentType(ServerResponseWriter.java:186)
2015-01-31T01:06:37.924507+00:00 app[web.1]:    at org.jboss.resteasy.core.ServerResponseWriter.writeNomapResponse(ServerResponseWriter.java:46)
2015-01-31T01:06:37.924509+00:00 app[web.1]:    at org.jboss.resteasy.core.SynchronousDispatcher.writeResponse(SynchronousDispatcher.java:427)
2015-01-31T01:06:37.924510+00:00 app[web.1]:    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:376)
2015-01-31T01:06:37.924550+00:00 app[web.1]:    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179)
2015-01-31T01:06:37.924552+00:00 app[web.1]:    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:220)
2015-01-31T01:06:37.924554+00:00 app[web.1]:    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:56)
2015-01-31T01:06:37.924556+00:00 app[web.1]:    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:51)
2015-01-31T01:06:37.924558+00:00 app[web.1]:    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
2015-01-31T01:06:37.924559+00:00 app[web.1]:    at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:751)
2015-01-31T01:06:37.924561+00:00 app[web.1]:    at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:566)
2015-01-31T01:06:37.924562+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
2015-01-31T01:06:37.924564+00:00 app[web.1]:    at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:578)
2015-01-31T01:06:37.924566+00:00 app[web.1]:    at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221)
2015-01-31T01:06:37.924567+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1111)
2015-01-31T01:06:37.924570+00:00 app[web.1]:    at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183)
2015-01-31T01:06:37.924572+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1045)
2015-01-31T01:06:37.924569+00:00 app[web.1]:    at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:498)
2015-01-31T01:06:37.924573+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
2015-01-31T01:06:37.924575+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:199)
2015-01-31T01:06:37.924576+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:109)
2015-01-31T01:06:37.924578+00:00 app[web.1]:    at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:98)
2015-01-31T01:06:37.924579+00:00 app[web.1]:    at org.eclipse.jetty.server.Server.handle(Server.java:461)
2015-01-31T01:06:37.924581+00:00 app[web.1]:    at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:284)
2015-01-31T01:06:37.924582+00:00 app[web.1]:    at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)
2015-01-31T01:06:37.924584+00:00 app[web.1]:    at org.eclipse.jetty.io.AbstractConnection.run(AbstractConnection.java:534)
2015-01-31T01:06:37.924586+00:00 app[web.1]:    at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:607)
2015-01-31T01:06:37.924587+00:00 app[web.1]:    at org.eclipse.jetty.util.thread.QueuedThreadPool.run(QueuedThreadPool.java:536)
2015-01-31T01:06:37.924594+00:00 app[web.1]:    at java.lang.Thread.run(Thread.java:745)

这是我的 mvn dependency:tree

[INFO] --- maven-dependency-plugin:2.4:tree (default-cli) @ crewdriver ---
[INFO] com.getworkers:crewdriver:war:1.2-SNAPSHOT
[INFO] +- org.jboss.resteasy:resteasy-jaxrs:jar:3.0.9.Final:compile
[INFO] |  +- org.jboss.resteasy:jaxrs-api:jar:3.0.9.Final:compile
[INFO] |  +- org.jboss.spec.javax.annotation:jboss-annotations-api_1.1_spec:jar:1.0.1.Final:compile
[INFO] |  +- javax.activation:activation:jar:1.1:compile
[INFO] |  \- net.jcip:jcip-annotations:jar:1.0:compile
[INFO] +- org.jboss.resteasy:resteasy-client:jar:3.0.9.Final:compile
[INFO] +- org.jboss.resteasy:resteasy-jaxb-provider:jar:3.0.9.Final:compile
[INFO] |  \- com.sun.xml.bind:jaxb-impl:jar:2.2.7:compile
[INFO] |     +- com.sun.xml.bind:jaxb-core:jar:2.2.7:compile
[INFO] |     |  +- javax.xml.bind:jaxb-api:jar:2.2.7:compile
[INFO] |     |  \- com.sun.istack:istack-commons-runtime:jar:2.16:compile
[INFO] |     \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12:compile
[INFO] |        \- javax.xml.bind:jsr173_api:jar:1.0:compile
[INFO] +- org.jboss.resteasy:resteasy-jackson-provider:jar:3.0.9.Final:compile
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.9.12:compile
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.12:compile
[INFO] |  +- org.codehaus.jackson:jackson-jaxrs:jar:1.9.12:compile
[INFO] |  \- org.codehaus.jackson:jackson-xc:jar:1.9.12:compile
[INFO] +- org.jboss.resteasy:resteasy-servlet-initializer:jar:3.0.9.Final:compile
[INFO] |  \- org.jboss.resteasy:async-http-servlet-3.0:jar:3.0.9.Final:compile
[INFO] +- org.eclipse.jetty.orbit:javax.servlet:jar:3.0.0.v201112011016:provided
[INFO] +- net.spy:spymemcached:jar:2.11.4:compile
[INFO] +- com.google.code.gson:gson:jar:2.2.4:compile
[INFO] +- com.sun.jersey:jersey-client:jar:1.18.1:compile
[INFO] |  \- com.sun.jersey:jersey-core:jar:1.18.1:compile
[INFO] +- net.fckeditor:java-core:jar:2.6:compile
[INFO] |  +- org.devlib.schmidt:imageinfo:jar:1.9:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.5.8:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.31:compile
[INFO] +- com.twilio.sdk:twilio-java-sdk:jar:3.3.15:compile
[INFO] |  \- com.googlecode.json-simple:json-simple:jar:1.1:compile
[INFO] +- com.github.spullara.mustache.java:compiler:jar:0.8.15:compile
[INFO] |  \- com.google.guava:guava:jar:16.0.1:compile
[INFO] +- commons-lang:commons-lang:jar:2.6:compile
[INFO] +- commons-io:commons-io:jar:2.4:compile
[INFO] +- commons-fileupload:commons-fileupload:jar:1.3.1:compile
[INFO] +- org.slf4j:slf4j-log4j12:jar:1.7.7:compile
[INFO] |  \- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.slf4j:slf4j-simple:jar:1.7.7:compile
[INFO] +- com.newrelic.agent.java:newrelic-agent:jar:3.5.1:provided
[INFO] +- com.sendgrid:sendgrid-java:jar:1.0.0:compile
[INFO] |  +- org.json:json:jar:20140107:compile
[INFO] |  \- com.mashape.unirest:unirest-java:jar:1.3.8:compile
[INFO] |     \- org.apache.httpcomponents:httpasyncclient:jar:4.0.1:compile
[INFO] |        \- org.apache.httpcomponents:httpcore-nio:jar:4.3.2:compile
[INFO] +- com.sendgrid:smtpapi-java:jar:0.0.2:compile
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.3.3:compile
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.3.2:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] |  \- commons-codec:commons-codec:jar:1.6:compile
[INFO] +- org.apache.httpcomponents:httpmime:jar:4.3.3:compile
[INFO] +- commons-validator:commons-validator:jar:1.4.0:compile
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.8.3:compile
[INFO] |  \- commons-digester:commons-digester:jar:1.8:compile
[INFO] +- org.eclipse.jetty.aggregate:jetty-all:jar:9.2.1.v20140609:compile
[INFO] |  +- javax.websocket:javax.websocket-api:jar:1.0:compile
[INFO] |  \- javax.servlet:javax.servlet-api:jar:3.1.0:compile
[INFO] +- org.eclipse.jetty:jetty-plus:jar:9.2.1.v20140609:compile
[INFO] |  \- org.eclipse.jetty:jetty-jndi:jar:9.2.1.v20140609:compile
[INFO] +- org.eclipse.jetty:jetty-webapp:jar:9.2.1.v20140609:compile
[INFO] |  \- org.eclipse.jetty:jetty-xml:jar:9.2.1.v20140609:compile
[INFO] +- org.eclipse.jetty:jetty-servlet:jar:9.2.1.v20140609:compile
[INFO] |  \- org.eclipse.jetty:jetty-security:jar:9.2.1.v20140609:compile
[INFO] |     \- org.eclipse.jetty:jetty-server:jar:9.2.1.v20140609:compile
[INFO] |        +- org.eclipse.jetty:jetty-http:jar:9.2.1.v20140609:compile
[INFO] |        \- org.eclipse.jetty:jetty-io:jar:9.2.1.v20140609:compile
[INFO] +- org.eclipse.jetty:jetty-util:jar:9.2.1.v20140609:compile
[INFO] +- org.eclipse.jdt:core:jar:3.3.0-v_771:compile
[INFO] |  +- org.eclipse.core:resources:jar:3.3.0-v20070604:compile
[INFO] |  |  \- org.eclipse.core:expressions:jar:3.3.0-v20070606-0010:compile
[INFO] |  +- org.eclipse.core:runtime:jar:3.10.0-v20140318-2214:compile
[INFO] |  |  +- org.eclipse:osgi:jar:3.10.0-v20140606-1445:compile
[INFO] |  |  +- org.eclipse.equinox:common:jar:3.6.200-v20130402-1505:compile
[INFO] |  |  +- org.eclipse.core:jobs:jar:3.6.0-v20140424-0053:compile
[INFO] |  |  +- org.eclipse.equinox:registry:jar:3.5.400-v20140428-1507:compile
[INFO] |  |  +- org.eclipse.equinox:preferences:jar:3.5.200-v20140224-1527:compile
[INFO] |  |  +- org.eclipse.core:contenttype:jar:3.4.200-v20140207-1251:compile
[INFO] |  |  \- org.eclipse.equinox:app:jar:1.3.200-v20130910-1609:compile
[INFO] |  +- org.eclipse.core:filesystem:jar:1.1.0-v20070606:compile
[INFO] |  \- org.eclipse:text:jar:3.3.0-v20070606-0010:compile
[INFO] |     \- org.eclipse.core:commands:jar:3.3.0-I20070605-0010:compile
[INFO] +- net.integrio:tools:jar:1.0:compile
[INFO] +- xdo:xdocore:jar:1.0:compile
[INFO] +- net.integrio:integrio-db:jar:1.1:compile
[INFO] +- net.integrio:integrio-db-ext:jar:1.2:compile
[INFO] +- net.integrio:integrio-js:jar:1.3.0.6:compile
[INFO] +- net.integrio:integrio-json:jar:1.1:compile
[INFO] +- net.integrio:integrio-utils:jar:1.2:compile
[INFO] +- net.integrio:integrio-web-tags:jar:1.2:compile
[INFO] +- net.integrio:integrio-web:jar:1.2:compile
[INFO] +- org.apache.commons:commons-lang3:jar:3.3.2:compile
[INFO] \- javax.inject:javax.inject:jar:1:compile

Is it possible that lack of memory will cause a NoSuchMethodError?

A从技术角度想不出会发生的方式。内存不足会导致 OutOfMemoryError 异常。即使有 "squashed" 它们,对 class 加载的潜在损害也会导致异常,说 class 无法加载……不是这个。

当您尝试加载某些 class 的不兼容版本时,会发生 NoSuchMethodError。具体来说,一个 class 在第二个 class 上调用了一个方法,并且该方法不再存在......在 class 代码的版本中 class加载程序已找到。

您应该检查您在运行时使用的包含 BuiltResponse 的 JAR 是否与您构建代码所依据的 JAR 相同。

这也可能是您正在使用的某些库之间的版本不匹配。


Everything seems to work fine without the background process turned on, however when I turn on the background process my application starts using more memory than the 512MB allocated and I'm immediately hit with NoSuchMethodErrors.

我怀疑额外的内存使用是在转移注意力。问题与后台进程代码及其依赖项有关。