Limit Java Heap Space for play framework globaly

前端 未结 9 1549
無奈伤痛
無奈伤痛 2020-12-04 14:22

I have a very old linux system and installed java and play framework. When I run java I get:

java -version
Error occurred during initialization of VM
Could n         


        
相关标签:
9条回答
  • 2020-12-04 15:24

    After googling more around I found this discussion. The problem is, that my Linux System is running in an openvz container:

    The reason why Java complains is because on start up, it sees that the machine has more than 2 GB of RAM, so it starts up in server mode, which tries to allocate all the memory, which then fails because it is inside a VPS.

    I could fix the java startup problem by changing /usr/java/jdk1.6.0_26/jre/lib/i386/jvm.cfg from:

    -client IF_SERVER_CLASS -server
    -server KNOWN
    -hotspot ALIASED_TO -client
    -classic WARN
    -native ERROR
    -green ERROR
    

    to:

    #-client IF_SERVER_CLASS -server
    -client KNOWN
    -server KNOWN
    -hotspot ALIASED_TO -client
    -classic WARN
    -native ERROR
    -green ERROR
    

    Now I can run any play command. Maybe this helps other people having similar problems related to container based virtualization.

    BR, Rene

    0 讨论(0)
  • 2020-12-04 15:27

    You computer doesn't have enough RAM to run Java. Java needs at least 64MB RAM.

    Note that you can't add free memory to your computer by specifying -Xms to Java: Java can't add memory modules to your mainboard. -Xms just tells Java how much of the available RAM to take. If that fails (= the OS returns an error when Java tries to allocate it), you get the error above.

    My guess is that there is no swap space. Look at the output of cat /proc/meminfo. Or you have a ulimit set which limits how much memory each process can allocate (try ulimit -a to check).

    0 讨论(0)
  • 2020-12-04 15:28

    Play does not appear to pick up the jvm.memory settings for dependencies or even test command. One way to force it to use specific JVM settings would be to use _JAVA_OPTIONS.

    For example:

    export _JAVA_OPTIONS="-Xms800m -Xmx1500m -XX:PermSize=64m -XX:MaxPermSize=256m"
    play test
    

    or

    play deps
    

    and you should see

    ~        _            _ 
    ~  _ __ | | __ _ _  _| |
    ~ | '_ \| |/ _' | || |_|
    ~ |  __/|_|\____|\__ (_)
    ~ |_|            |__/   
    ~
    ~ play! 1.2.3, http://www.playframework.org
    ~ framework ID is test
    ~
    ~ Running in test mode
    ~ Ctrl+C to stop
    ~ 
    Picked up _JAVA_OPTIONS: -Xms800m -Xmx1500m -XX:PermSize=64m -XX:MaxPermSize=256m
    Listening for transport dt_socket at address: 8000
    

    Note that this would apply those settings to all java programs run on that terminal where _JAVA_OPTIONS is set.

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