Java 增加 netbeans.conf 文件中的堆大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2015847/
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
increasing heap size in netbeans.conf file
提问by mrblah
I was reading in netbeans 6, you don't have to set the maximum heap size, it will just look at your computer for that information.
我正在阅读 netbeans 6,您不必设置最大堆大小,它只会查看您的计算机以获取该信息。
My system has 8 gigs of ram, but my application only has 64mb to play with and it is running out of memory.
我的系统有 8 演出内存,但我的应用程序只有 64mb 可用,而且内存不足。
I did a:
我做了一个:
System.out.println(Runtime.getRuntime().maxMemory());
System.out.println(Runtime.getRuntime().maxMemory());
And it is 66 650 112 bytes (63.5625 megabytes).
它是 66 650 112 字节(63.5625 兆字节)。
my netbeans.config:
我的 netbeans.config:
-J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m
I tried to change these numbers, but then netbeans failed to load (JVM error).
我试图更改这些数字,但是 netbeans 无法加载(JVM 错误)。
How can I increase the maximum size to 1 GB?
如何将最大大小增加到 1 GB?
采纳答案by Drewen
This command line give to your Java program a 64Mb initial and 256Mb maximum heap size.
此命令行为您的 Java 程序提供 64Mb 的初始堆大小和 256Mb 的最大堆大小。
java -Xms64m -Xmx256m jdbc_prog
Good luck!
祝你好运!
回答by Bob Cross
EDIT: responding to the comment
编辑:回应评论
If your application has a specific need for heap space, you can set the virtual machine parameters that you would like it to use. For example, I have a default maximum heap size that I use in the default run configuration. I also have larger maximums for run configurations where I know that I will be processing more data.
如果您的应用程序对堆空间有特定需求,您可以设置您希望它使用的虚拟机参数。例如,我有一个在默认运行配置中使用的默认最大堆大小。我也有更大的运行配置最大值,我知道我将处理更多数据。
You can access the run configurations several ways:
您可以通过多种方式访问运行配置:
- Right click the project (under Projects) and select "Properties." Click "Run" and notice the "VM options" text field that appears on the right. If you add "-Xmx1024" to that field, you will allow the heap to grow to a maximum size of 1024 megabytes.
- You can also customize the run configurations directly from the combo box in the "Run" toolbar. If you click the combo box, you'll see that the last choice is "Customize." This will bring up the same dialog box.
- 右键单击项目(在项目下)并选择“属性”。单击“运行”并注意右侧显示的“VM 选项”文本字段。如果将“-Xmx1024”添加到该字段,您将允许堆增长到 1024 兆字节的最大大小。
- 您还可以直接从“运行”工具栏中的组合框中自定义运行配置。如果单击组合框,您将看到最后一个选项是“自定义”。这将打开相同的对话框。
It is important to note that setting the maximum heap size does not immediately allocate that much memory. With my current work, I prefer to allow the heap to grow up to the maximum if necessary but also, to be a good neighbor with other services on the machine, I allow it to keep a small heap if things fit. You can, however, specify that heap size should start at the maximum possible size by using the -Xms option.
需要注意的是,设置最大堆大小不会立即分配那么多内存。在我目前的工作中,我更愿意在必要时允许堆增长到最大值,但为了与机器上的其他服务成为一个好邻居,如果情况合适,我允许它保留一个小堆。但是,您可以使用 -Xms 选项指定堆大小应从可能的最大大小开始。
For example, if you set the virtual machine options to "-Xms1024m -Xmx1024m", the application will grab the entire gig of memory on startup and hold it for the entire run.
例如,如果您将虚拟机选项设置为“-Xms1024m -Xmx1024m”,应用程序将在启动时获取整个内存并在整个运行过程中保留它。
End EDIT
结束编辑
If you'd like to ensure that Netbeans always has enough heap space, you can do this one of two easy ways. One is to modify the netbeans.conf file. In mine, the original line reads like so:
如果您想确保 Netbeans 始终有足够的堆空间,您可以使用以下两种简单方法之一。一种是修改netbeans.conf文件。在我的,原始行是这样写的:
netbeans_default_options="-J-client -J-Xverify:none -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true"
netbeans_default_options="-J-client -J-Xverify:none -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J- Dsun.java2d.noddraw=true"
If you would like to give Netbeans up to one gig of RAM to play with, you can change the line to read like so:
如果您想给 Netbeans 最多一演出 RAM 来玩,您可以将行更改为如下所示:
netbeans_default_options="-J-client -J-Xverify:none -J-Xmx1024m -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=true -J-Dsun.java2d.noddraw=true"
netbeans_default_options="-J-client -J-Xverify:none -J-Xmx1024m -J-Xss2m -J-Xms32m -J-XX:PermSize=32m -J-XX:MaxPermSize=200m -J-Dapple.laf.useScreenMenuBar=真-J-Dsun.java2d.noddraw=真"
where the "-J-Xmx1024m" argument will allow the heap to grow up to a size of 1024 meg.
其中“-J-Xmx1024m”参数将允许堆增长到 1024 兆的大小。
However, it's even easier to set the max heap for Netbeans at runtime from a launcher or shortcut. On my machine, I have a launcher that passes the max heap in directly without changing the configuration file:
但是,在运行时从启动器或快捷方式为 Netbeans 设置最大堆更容易。在我的机器上,我有一个启动器,可以直接传入最大堆而不更改配置文件:
/usr/local/netbeans-6.8/bin/netbeans -J-Xmx1024m
/usr/local/netbeans-6.8/bin/netbeans -J-Xmx1024m
Feel free to use whichever is most convenient for you.
随意使用对您来说最方便的那个。
回答by Sudhakar Krishnan
The easy way. Go to
简单的方法。去
/usr/share/applications
/usr/share/应用程序
Check if netbeansfile exist there, " if there is no netbeans file - select any other file(ex: termianl)"and copy netbeans file(if not terminal file) to desktop. {Don't move - if any error you can change later.}
检查NetBeans的文件存在在那里,“如果没有NetBeans的文件-选择的任何其他文件(例如:吡嗪酰胺)”和NetBeans文件(如果不是终端文件)拷贝到桌面。{不要移动 - 如果有任何错误,您可以稍后更改。}
Open this file(netbeans or terminal) in text editor(gedit). Replace its content to.
在文本编辑器(gedit)中打开此文件(netbeans 或终端)。将其内容替换为。
[Desktop Entry]
Encoding=UTF-8
Name=NetBeans IDE 7.4
Comment=The Smarter Way to Code
Exec=/opt/netbeans-7.4/bin/netbeans -J-Xmx1024m
Icon=/opt/netbeans-7.4/nb/netbeans.png
Categories=Application;Development;Java;IDE
Version=1.0
Type=Application
Terminal=0
GenericName[en_IN]=Custom NB Launcher
CheckExec : is it point to correct netbeans location, also Icon : to set the icon.
检查Exec :是否指向正确的 netbeans 位置,还有 Icon :设置图标。
IMPORTANT :
重要的 :
Don't forget to modify Exec : -J-Xmx1024m
不要忘记修改 Exec : -J-Xmx1024m
In this change 1024 according to your ram size.
在此根据您的 ram 大小更改 1024。