Appropriate place in catalina.bat to set JAVA_OPTS

前端 未结 5 1880
天涯浪人
天涯浪人 2020-12-31 20:12

I got the below error

\"java.lang.OutOfMemoryError: PermGen space\"

In my catalina.bat file, where is the appropriate place f

相关标签:
5条回答
  • 2020-12-31 20:48

    Please read this: OutOfMemory Error and make sure your application doesn't have memory leak and excessive memory usage.

    To change the settings, create a file named setenv.bat for windows or setenv.sh for Linux with entry as below:

    Windows:

    set JAVA_OPTS="-Xms256m -Xmx512m"
    

    Linux:

    export JAVA_OPTS="-Xms256m -Xmx512m"
    

    Simply put this(setenv.bat/setenv.sh) file in %CATALINA_HOME%\bin\ folder. Your command file (catalina.bat/catalina.sh) already has a statement as below:

    Windows:

      if exist "%CATALINA_HOME%\bin\setenv.bat" call "%CATALINA_HOME%\bin\setenv.bat"
    

    Linux:

      if [ -r "$CATALINA_BASE/bin/setenv.sh" ]; then
         . "$CATALINA_BASE/bin/setenv.sh"
      elif [ -r "$CATALINA_HOME/bin/setenv.sh" ]; then
         . "$CATALINA_HOME/bin/setenv.sh"
      fi
    

    This will take care the rest.

    0 讨论(0)
  • 2020-12-31 20:54

    The proper place is to create a new file in the Tomcat /bin directory alongside catalina.bat, named setenv.bat and place a set JAVA_OPTS=... there.

    On *nix system it'd be setenv.sh

    catalina.bat/catalina.sh takes care of running setenv.bat/setenv.sh if it exists. This is noted in the section 3.4 here

    0 讨论(0)
  • 2020-12-31 20:54

    Like others have already suggested you need to use JAVA_OPTS set to something like: JAVA_OPTS="-XX:MaxPermSize=98m". This, alone, will probably solve the issues, but if you are redeploying a lot of times and your war/jar is huge you will hit this memory limit too.

    For this last scenario, something normal on a test/devel machines, I recommend using:

    -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC

    This options will enable the unloading of the unused classes.

    Look here more details, especially the comments.

    0 讨论(0)
  • 2020-12-31 20:54

    In your environment. Our you could create a wrapper script that sets JAVA_OPTS then calls the catalina script.

    0 讨论(0)
  • 2020-12-31 20:55

    This happened because you redeployed several times. You can increase your perm gen space, but it'll only delay the inevitable error.

    You'll just have to restart your server. I'm not aware of a workaround.

    0 讨论(0)
提交回复
热议问题