I am trying to build a lexicon trie of almost 110000 words in java in netbeans. My code is running fine but it gives an Exception as follows:
我试图在netbeans中用java构建一个近110000个单词的词典。我的代码运行正常,但它给出了一个异常,如下所示:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOfRange(Arrays.java:3209)
at java.lang.String.<init>(String.java:215)
at java.nio.HeapCharBuffer.toString(HeapCharBuffer.java:542)
at java.nio.CharBuffer.toString(CharBuffer.java:1157)
at java.util.regex.Matcher.toMatchResult(Matcher.java:232)
at java.util.Scanner.match(Scanner.java:1270)
at java.util.Scanner.nextLine(Scanner.java:1517)
at lexiconbuild.model.Lexicon.<init>(Lexicon.java:29)
at lexiconbuild.model.LexiconBuild.main(LexiconBuild.java:17)
Java Result: 1
I was wondering if someone could help me with increasing the java heap space in netbeans.
我想知道是否有人可以帮助我增加netbeans中的Java堆空间。
3 个解决方案
#1
47
You can set it in NetBeans in the project properties -> Run -> VM options
您可以在项目属性 - >运行 - > VM选项中的NetBeans中进行设置
- Right click on your project "Properties"
- Select "Run" category.
- Enter your arguments(-Xmx512m) in the "VM Options" text box.
右键单击您的项目“属性”
选择“运行”类别。
在“VM选项”文本框中输入参数(-Xmx512m)。
Example: Putting -Xmx512m in the "VM Options" text box gives 512Mb maximum heap size to your Java program.
示例:在“VM Options”文本框中放置-Xmx512m可为Java程序提供512Mb的最大堆大小。
#2
30
if you want to change it for netbeans it self you can change it from this file:
如果你想为netbeans改变它自己,你可以从这个文件更改它:
netbeans.conf
you will find it in netbeans folder under /etc
你会在/ etc下的netbeans文件夹中找到它
and there is two parameters for the heap
并且堆有两个参数
Xms - the initial size of the heap.
Xms - 堆的初始大小。
Xmx - max java heap size
Xmx - 最大java堆大小
it using the default, you just have to add it there and try to add them both.
它使用默认值,你只需要在那里添加它并尝试添加它们。
and also don't forget to add those to netbeans_default_options when you change the XMX
并且在更改XMX时也不要忘记将这些添加到netbeans_default_options
-J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled
so netbeans_default_options will be something like that:
所以netbeans_default_options将是这样的:
netbeans_default_options="-J-client -J-Xss2m -J-Xms512m -J-Xmx1024m -J-XX:PermSize=256m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled"
#3
3
In the run configuration you should set Java VM option -Xmx512m
or other that limits the maximum size of the Java VM to 512M. You can always experiment with other values. You are only limited with physical memory used by the OS.
在运行配置中,您应该将Java VM选项-Xmx512m或其他将Java VM的最大大小限制为512M。您始终可以尝试其他值。您仅限于操作系统使用的物理内存。
#1
47
You can set it in NetBeans in the project properties -> Run -> VM options
您可以在项目属性 - >运行 - > VM选项中的NetBeans中进行设置
- Right click on your project "Properties"
- Select "Run" category.
- Enter your arguments(-Xmx512m) in the "VM Options" text box.
右键单击您的项目“属性”
选择“运行”类别。
在“VM选项”文本框中输入参数(-Xmx512m)。
Example: Putting -Xmx512m in the "VM Options" text box gives 512Mb maximum heap size to your Java program.
示例:在“VM Options”文本框中放置-Xmx512m可为Java程序提供512Mb的最大堆大小。
#2
30
if you want to change it for netbeans it self you can change it from this file:
如果你想为netbeans改变它自己,你可以从这个文件更改它:
netbeans.conf
you will find it in netbeans folder under /etc
你会在/ etc下的netbeans文件夹中找到它
and there is two parameters for the heap
并且堆有两个参数
Xms - the initial size of the heap.
Xms - 堆的初始大小。
Xmx - max java heap size
Xmx - 最大java堆大小
it using the default, you just have to add it there and try to add them both.
它使用默认值,你只需要在那里添加它并尝试添加它们。
and also don't forget to add those to netbeans_default_options when you change the XMX
并且在更改XMX时也不要忘记将这些添加到netbeans_default_options
-J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled
so netbeans_default_options will be something like that:
所以netbeans_default_options将是这样的:
netbeans_default_options="-J-client -J-Xss2m -J-Xms512m -J-Xmx1024m -J-XX:PermSize=256m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.zip.disableMemoryMapping=true -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled"
#3
3
In the run configuration you should set Java VM option -Xmx512m
or other that limits the maximum size of the Java VM to 512M. You can always experiment with other values. You are only limited with physical memory used by the OS.
在运行配置中,您应该将Java VM选项-Xmx512m或其他将Java VM的最大大小限制为512M。您始终可以尝试其他值。您仅限于操作系统使用的物理内存。