如何永久增加java堆内存? [英] how to increase java heap memory permanently?

查看:991
本文介绍了如何永久增加java堆内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java堆内存问题。我在java中开发了一个客户端服务器应用程序,它作为Windows服务运行,需要超过512MB的内存。我有2GB的RAM但是当我运行我的应用程序时会抛出异常

I have one problem with java heap memory. I developed one client server application in java which is run as a windows service it requires more than 512MB of memory. I have 2GB of RAM but when I run my application it throws an exception


内存不足错误:java堆空间

Out of memory error:java heap space

但是我已经在java控制面板中设置了堆大小(最大512MB),我仍然得到相同的错误。我无法通过命令行设置堆大小,因为我的应用程序作为Windows服务运行,所以如何增加默认堆大小?

but I have already set heap size (maximum 512MB) in the java control panel and I still get the same error. I can't set heap size through the command line because my application runs as a windows service so how can I increase the default heap size?

推荐答案

请注意,在 java之后增加Java堆大小.lang.OutOfMemoryError:Java堆空间通常只是一个短期解决方案。

Please note that increasing the Java heap size following an java.lang.OutOfMemoryError: Java heap space is quite often just a short term solution.

这意味着即使您将默认Java堆大小从512 MB增加到2048 MB,如果您正在处理,您仍可能在某些时候出现此错误内存泄漏。要问的主要问题是为什么你首先得到这个OOM错误?它真的是Xmx值太低还是仅仅是另一个问题的症状?

This means that even if you increase the default Java heap size from 512 MB to let's say 2048 MB, you may still get this error at some point if you are dealing with a memory leak. The main question to ask is why are you getting this OOM error at the first place? Is it really a Xmx value too low or just a symptom of another problem?

在开发Java应用程序时,了解其静态和动态内存占用要求始终至关重要在早期,这将有助于防止以后复杂的OOM问题。正确选择JVM Xms& Xmx设置可以通过适当的应用程序分析和负载测试来实现。

When developing a Java application, it is always crucial to understand its static and dynamic memory footprint requirement early on, this will help prevent complex OOM problems later on. Proper sizing of JVM Xms & Xmx settings can be achieved via proper application profiling and load testing.

这篇关于如何永久增加java堆内存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆