【问题标题】:Grails - severe IllegalStateException - Method on class [] was used outside of a Grails applicationGrails - 严重的 IllegalStateException - 类 [] 上的方法在 Grails 应用程序之外使用
【发布时间】:2013-02-08 10:37:30
【问题描述】:

我在 prod 环境中遇到严重的 IllegalStateException 错误(底部的堆栈跟踪)。在本地,在 dev 上一切正常,我在本地从未遇到过这段代码的任何问题。

Prod 和 Dev 配置具有相同的 Tomcat 5。在 dev 上我有 PostgreSQL 9.2 和 prod 8.4。 Pod 环境是某些主机上的 VPS。

导致它的代码是一个简单的类实例创建者(GameStateTransition 类)——它负责初始化和保存超过 370 000 个实例。导致错误的行是 save(flush:true) 或 hibernateSesion.flush() - 我尝试了这两个选项。

错误发生的不确定性 - 有时在创建 160 000 个实例之后,有时在 220 000 之后,有时在 300 000 之后...

我认为这可能是内存问题,并且 VPS 服务器杀死了最消耗内存的进程,但是将 JAVA_OPTS Xmx 更改为 256m,这远低于服务器的 500m 限制,但没有帮助。在本地运行应用程序并将开发数据库更改为生产 Postgres 8.4 工作正常(过程完成且没有错误),因此它一定是产品服务器上的应用程序有问题。

谁有任何线索,可能是关于什么的?

stacktrace 说的是关于 mongoDB、测试和模拟注释的内容,但我没有使用其中任何一个。这是一个创建实例并将其保存到数据库的简单代码。

2013-02-08 00:07:50 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["http-bio-12200"]
2013-02-08 00:07:50 org.apache.coyote.AbstractProtocol pause
INFO: Pausing ProtocolHandler ["ajp-bio-8009"]
2013-02-08 00:07:50 org.apache.catalina.core.StandardService stopInternal
INFO: Stopping service Catalina
2013-02-08 00:07:50 org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated
2013-02-08 00:07:51 org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated
2013-02-08 00:07:52 org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated
2013-02-08 00:07:52 org.apache.catalina.core.StandardWrapper unload
INFO: Waiting for 1 instance(s) to be deallocated
2013-02-08 00:07:52,979 [http-bio-12200-exec-6] ERROR errors.GrailsExceptionResolver  - IllegalStateException occurred when processing request: [GET] /gameState/initializeTransitionMatrix
Method on class [pl.edu.caspar.analyzer.GameStateTransition] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.. Stacktrace follows:
 java.lang.IllegalStateException: Method on class [pl.edu.caspar.analyzer.GameStateTransition] was used outside of a Grails application. If running in the context of a test using the mocking API or bootstrap Grails correctly.
    at org.grails.datastore.mapping.engine.event.AbstractPersistenceEventListener.onApplicationEvent(AbstractPersistenceEventListener.java:46)
    at pl.edu.caspar.analyzer.GameStateController$_initializeTransitionMatrix_closure3_closure8.doCall(GameStateController.groovy:59)
    at pl.edu.caspar.analyzer.GameStateController$_initializeTransitionMatrix_closure3.doCall(GameStateController.groovy:53)
    at pl.edu.caspar.analyzer.GameStateController.initializeTransitionMatrix(GameStateController.groovy:52)
    at grails.plugin.cache.web.filter.PageFragmentCachingFilter.doFilter(PageFragmentCachingFilter.java:195)
    at grails.plugin.cache.web.filter.AbstractFilter.doFilter(AbstractFilter.java:63)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)

【问题讨论】:

    标签: hibernate exception tomcat grails


    【解决方案1】:

    鉴于

    2013-02-08 00:07:50 org.apache.catalina.core.StandardService stopInternal
    INFO: Stopping service Catalina
    2013-02-08 00:07:50 org.apache.catalina.core.StandardWrapper unload
    INFO: Waiting for 1 instance(s) to be deallocated
    

    这看起来像 Tomcat 进程由于某种原因试图关闭,当您尝试在正在关闭的应用程序中执行控制器操作时发生异常。

    你这么说

    我认为这可能是内存问题和 VPS 服务器杀死了最消耗内存的进程,但是将 JAVA_OPTS Xmx 更改为 256m,这远低于服务器的 500m 限制,没有帮助

    Java 内存不仅仅是堆大小 (-Xmx),还有 PermGen 大小 (-XX:MaxPermSize=...) 和堆栈空间的其他设置等。您可能还需要限制这些以保持整个进程低于 VPS 内存限制。

    【讨论】:

    • 是的,我也想到了——我将 MaxPermSize 设置为 128m,现在该过程正在运行——在 20-30 分钟内我们应该有一个答案:)您会建议研究其他内存设置吗?
    • @Makaveli -Xss 用于每个线程的堆栈大小,但我不知道默认值是什么。您还可以查看在 server.xml 中调整 Tomcat 线程池设置。
    • 好的,现在我 100% 确定这是内存不足的问题,但无论我如何使用调整参数,该过程总是失败。这意味着我的 Grails 代码可能是错误的 - 我将它作为另一个问题发布在 ST (stackoverflow.com/questions/14774799/…) 上,并将在该级别上寻求一些帮助。非常感谢伊恩的帮助。
    猜你喜欢
    • 2014-02-21
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多