在 Apache Karaf 下设置 Java 堆大小

发布于 2024-12-03 12:54:00 字数 282 浏览 1 评论 0原文

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

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

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

set DEFAULT_JAVA_OPTS=-server -XmxM

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

谢谢

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?

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

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.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

慕巷 2024-12-10 12:54:00

(至少)在 karaf 2.2.10 中:

如果通过 bin/start 运行 karaf

正如 FordGuo 指出的,可以在 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

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

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

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

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

(At least) in karaf 2.2.10:

If running karaf through bin/start

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

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)

In this case any exported variable seems to be ignored.

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

# Maximum Java Heap Size (in MB)
wrapper.java.maxmemory=1024
终止放荡 2024-12-10 12:54:00

更新到 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
)

这意味着只需创建一个系统变量即可,而无需修改 bat 文件。

Updating to Karaf 2.2.3 reveals a new bat file.

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.

余生共白头 2024-12-10 12:54:00

这就是我在你的情况下会做的。

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

我喜欢使用网络控制台,因此我对其进行了更改,以便它为它启动的应用程序读取 karaf.vmoptions 文件。这需要修补代码,但事实证明它非常有用。

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.

旧时浪漫 2024-12-10 12:54:00

在bin目录下,有一个setenv(.bat)文件,
您可以在那里设置最大/最小内存。

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

樱花落人离去 2024-12-10 12:54:00

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 

在重新启动之前检查:

# 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';

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

# 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';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文