在 Apache Karaf 下设置 Java 堆大小

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7353981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:37:45  来源:igfitidea点击:

Setting Java Heap Size under Apache Karaf

javaheapapache-karaf

提问by Tony

I apologize if this is a duplicate, but I can't seem to find this answered anywhere.

如果这是重复的,我深表歉意,但我似乎无法在任何地方找到答案。

What is the best way to increase the maximum Java heap size when using Apache Karaf?

使用 Apache Karaf 时增加最大 Java 堆大小的最佳方法是什么?

Currently, I modified the following line in the karaf.bat file:

目前,我修改了 karaf.bat 文件中的以下行:

set DEFAULT_JAVA_OPTS=-server -Xmx<NewMaxValue>M.

set DEFAULT_JAVA_OPTS=-server -Xmx<NewMaxValue>M.

I feel like modifying the bat file is not the best solution. Additionally, none of the config files seem to have a place to put this.

我觉得修改bat文件不是最好的解决方案。此外,似乎没有一个配置文件有放置它的地方。

Thanks

谢谢

采纳答案by Tony

Updating to Karaf 2.2.3 reveals a new bat file.

更新到 Karaf 2.2.3 会显示一个新的 bat 文件。

if "%JAVA_MIN_MEM%" == "" (
    set JAVA_MIN_MEM=128M
)

if "%JAVA_MAX_MEM%" == "" (
    set JAVA_MAX_MEM=512M
)

if "%JAVA_PERM_MEM%" == "" (
    set JAVA_PERM_MEM=16M
)

if "%JAVA_MAX_PERM_MEM%" == "" (
    set JAVA_MAX_PERM_MEM=64M
)

This means one can just create a system variable instead of modifying the bat file.

这意味着您可以只创建一个系统变量而不是修改 bat 文件。

回答by el.atomo

(At least) in karaf 2.2.10:

(至少)在 karaf 2.2.10 中:

If running karaf through bin/start

如果运行 karaf bin/start

As Ford Guo pointed out, memory values could be configured in the bin/setenvfile:

正如 Ford Guo 指出的那样,可以在bin/setenv文件中配置内存值:

export JAVA_MIN_MEM=256M # Minimum memory for the JVM
export JAVA_MAX_MEM=1024M # Maximum memory for the JVM
export JAVA_PERM_MEM=128M # Minimum perm memory for the JVM
export JAVA_MAX_PERM_MEM=256M # Maximum memory for the JVM

If running karaf as a service (karaf-service)

如果将 karaf 作为服务运行 ( karaf-service)

In this case any exported variable seems to be ignored.

在这种情况下,任何导出的变量似乎都被忽略了。

The maximum java heap size could be defined in the etc/karaf-wrapper.conf:

最大 java 堆大小可以定义在etc/karaf-wrapper.conf

# Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=1024

回答by Ford Guo

in the bin directory ,there is a setenv(.bat) file, you can set the max/min mem in there.

在 bin 目录中,有一个 setenv(.bat) 文件,您可以在其中设置 max/min mem。

回答by Peter Lawrey

That what I would do in your situation.

在你的情况下我会怎么做。

I have seen people suggest using a service start which allows you define the the command line arguments.

我看到有人建议使用允许您定义命令行参数的服务启动。

I liked using the webconsole so I changed it so it read a karaf.vmoptions file for the applications it starts. This requires patching the code, but it turned out to be very useful.

我喜欢使用 webconsole,所以我对其进行了更改,以便它为它启动的应用程序读取 karaf.vmoptions 文件。这需要修补代码,但结果证明它非常有用。

回答by sjas

setenvwasnt loaded for me (using the karaf wrapper), so I put it into the wrapper config: (/opt/apache-servicemix-6.1.3/etc/karaf-wrapper.confin my case)

setenv没有为我加载(使用 karaf 包装器),所以我将它放入包装器配置中:(/opt/apache-servicemix-6.1.3/etc/karaf-wrapper.conf在我的情况下)

# JVM Parameters            
# note that n is the parameter number starting from 1.
wrapper.java.additional.1=-Dkaraf.home=%KARAF_HOME%
wrapper.java.additional.2=-Dkaraf.base=%KARAF_BASE%
wrapper.java.additional.3=-Dkaraf.data=%KARAF_DATA%
wrapper.java.additional.4=-Dkaraf.etc=%KARAF_ETC%
wrapper.java.additional.5=-Dcom.sun.management.jmxremote
wrapper.java.additional.6=-Dkaraf.startLocalConsole=false
wrapper.java.additional.7=-Dkaraf.startRemoteShell=true
wrapper.java.additional.8=-Djava.endorsed.dirs=%JAVA_HOME%/jre/lib/endorsed:%JAVA_HOME%/lib/endorsed:%KARAF_HOME%/lib/endorsed
wrapper.java.additional.9=-Djava.ext.dirs=%JAVA_HOME%/jre/lib/ext:%JAVA_HOME%/lib/ext:%KARAF_HOME%/lib/ext

# added by me
wrapper.java.additional.10=-XX:PermSize=512m 
wrapper.java.additional.11=-XX:MaxPermSize=512m 

Check prior to the restart:

重启前检查:

# get process id of you running instance
jps -lvm
# or
ps aux | grep java

# check memory before and after restarting the service to see wether it changed
jmap -heap $MY_PID 2>/dev/null | sed -ne '/Heap Configuration/,$p';