使用您的 JVM 内存设置,当您在本地计算机上以开发/测试模式运行时,它可能在尝试创建对象时内存不足,因此正在运行 GC 尝试回收内存并引发异常。这是一个项目中的 grails.project.fork 示例,我必须在启动时在 BootStrap.groovy 中创建很多对象:
grails.project.fork = [
// Configure settings for compilation JVM, note that if you alter the Groovy version forked compilation is required
// compile: [maxMemory: 256, minMemory: 64, debug: false, maxPerm: 256, daemon:true],
// Configure settings for the test-app JVM, uses the daemon by default
test: [maxMemory: 768, minMemory: 768, debug: false, maxPerm: 768, daemon:true],
// Configure settings for the run-app JVM
run: [maxMemory: 4560, minMemory: 1024, debug: false, maxPerm: 2560, forkReserve:false],
// Configure settings for the run-war JVM
war: [maxMemory: 4560, minMemory: 2560, debug: false, maxPerm: 2560, forkReserve:false],
// Configure settings for the Console UI JVM
console: [maxMemory: 768, minMemory: 64, debug: false, maxPerm: 256]
要尝试的另一件事是在 Tomcat 中使用更大的堆(例如 2 GB)运行应用程序,然后查看您的 GC 错误是否消失。顺便说一句,我发现 Grails 工作得更好,使用新的 G1 垃圾收集器和 JVM 上的 -server 标志。
从我的生产 Tomcat 7 实例的 setenv.sh 文件中:
export CATALINA_OPTS="$CATALINA_OPTS -Xms6g"
export CATALINA_OPTS="$CATALINA_OPTS -Xmx6g"
export CATALINA_OPTS="$CATALINA_OPTS -XX:+UseG1GC"
export CATALINA_OPTS="$CATALINA_OPTS -XX:MaxPermSize=768m"