Hibernate - OutOfMemoryError - java heap size - java

I'm currently having this problem where I am executing a query that will load large of records. At first execution, it is successful, but when I
execute again, I am having java heap size out of memory.
I Know I can increase java heap size using command line, but that requires a compiled jar file.
But I am currently on the development process, so how can I increase java heap size in that case?
Im using Elipse as my IDE.
Thanks for any response.

It doesn't require a compiled jar file. Choose Run - Run configurations... - Select your run configuration - Arguments tab. Then enter the appropriate command line argument in the VM arguments text box: -Xmx1024m for example.

You can modify the eclipse.ini file located inside of our eclipse directory .There you will find Xms40m Xmx256m parameter with some value , you can increase it to Xms256m Xmx1024m . Then check whether outofmemory error is still there . If its there then try tuning these parameter slightly increasing and check.

Apperently that was not enough for an answer... well, let me just copy the text from those answers instead :S
You can use the environment variable _JAVA_OPTIONS to set the default heap size. This will change the heap size for all Java programs. Like this:
export _JAVA_OPTIONS="-Xmx1g"

Related

Keep getting not enough space for object heap in java

I am trying to run the vFileServe of project anarchy, but i always have this error even though i set a parameter on my java
Here is my error
Loading deploy parameters from Source\Vision\Samples\Engine\FileServe\FileServe_
android_arm_vs2010_anarchy.vcxproj_Dev.deploy
Creating apkFile ../../../../../Bin/android_arm_vs2010_anarchy/Dev/libFileServe.
apk for library ../../../../../Bin/android_arm_vs2010_anarchy/Dev/libFileServe.s
o
Android platform (SDK) android-10
Removing dir AndroidTemp\armeabi-v7a
Making a raw (so uncompressed) dir for the gdb server, native .so etc...
Done
Generating classes.dex file
Error occurred during initialization of VM
Could not reserve enough space for object heap
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
Command finished with error code '1'
Here is my java parameter
I tried putting -XX:MaxHeapSize=256m -Xmx512m also but doesnt work either
Whats wrong here? Thanks
I don't know about this particular software but limiting JVM heap size to 512Mb max may be insufficient.
Try setting initial heap size to 512 Mb and maximum to 2 Gb with -Xms512m -Xmx2g
Fo some reason the environment variable of java has been removed. I have to set it again. That solve the problem

Is there a workaround to solve "Java heap space" memory error when the max heap value has been already specified?

I'm running a WEKA classifier (J48 with an input .arff file composed of 3 fields, field 1 has ~27k distinct attributes, field 2 ~ 500k values) in a latest generation Macbook Pro with 8GB RAM.
I increased the java heap space to the maximum possible using the -Xmx parameter:
java -Xmx7G -cp weka-3-6-10/weka.jar weka.classifiers.trees.J48 -t
myfiles/loc_linear.arff -i
however when I run the classifier (after about 10 minutes) I get the error "Exception in thread "main" java.lang.OutOfMemoryError: Java heap space".
Evidently 8GB RAM is not enough with my input file. Does this mean the only solution to this is having a more powerful hardware (e.g. 16GB RAM or a very powerful server/cluster)?
Would there be any workaround to this issue? (e.g. reducing the input file? If so, which would be in your opinion the criteria to apply in the reduction?). Any other ideas or suggestions?
If you are running the Weka GUI on a Mac OS X machine, you can edit a plist configuration file. I followed instructions from the Weka mailing list.
cd into /Applications/weka-XXX.app/Contents , or wherever your weka executable was installed.
There will be a file called Info.plist there. I suggest you save a copy of that file to another location, as you'll need to change it in the next step.
Open the weka-XXX.app/Contents/Info.plist (XML) file in your favorite text editor and look for a block that says "VMOptions". There should be a value that says "-Xmx256M" which specifies the memory. Change that value to something bigger, like "-Xmx1024M".
Start Weka.
From your cited line of code it seems you are running Weka from the simple command line interface. If that is the case, then the answer is the same as this [question] (Increase heap to avoid Out of Memory Error in WEKA.)
You can't increase the heap size from the command line interface. Instead I believe you should increase the heap size in the RunWeka.ini file as stated in Weka's instructions

Increase heap size in java for weka

I'm trying to increase the heap size in java for weka which keeps crashing. I used the suggested line:
> java -Xmx500m -classpath
but I get the following error:
-classpath requires class path specification
I'm not sure what this means. Any suggestions?
What I found was the actual issue was in the file 'RunWeka.ini' in '\Program Files (x86)\Weka-3-6'. I opened it with notepad and in the middle of the file there is a line 'maxheap = 512m'.
I changed the line to read 'maxheap=2000m', saved the file and reloaded weka and this fixed my problems.
I'm not sure if this is the correct way to do it or not but it worked for me.
Run this command in your terminal:
java -Xmx1024m -jar weka.jar
Omit the -classpath option. Use just -Xmx500m option.
So, instead of just:
java weka.core.Instances data/soybean.arff
you do:
java -Xmx500m weka.core.Instances data/soybean.arff
If you run weka via some script (RunWeka.bat for example), then you need to modify that script (with some text editor like notepad).
If you're using Weka 3.8.1 on Windows you can save yourself a lot of trouble by editing the javaOpts parameter. The parameter maxheap isn't used anymore, so you can set javaOpts like this in RunWeka.ini file:
javaOpts= -Xmx1040m
Where 1040m is the amount of memory you want to allocate.
Mind that the file is case sensitive.
There are a lot of ways to set this up, but this is the faster way to get Weka runing on a Windows environment at this version.
Edit: If you want Weka to use more than 1gb on windows, you need to have JDK installed. Regular JRE wont do it.
The official Weka answer (for all operating systems and Weka versions) can be found on http://weka.wikispaces.com/OutOfMemoryException.
In case you are using a recent Weka version on Windows, the answer is:
Modify the maxheap parameter in the RunWeka.ini file.
On Ubuntu i had the same problem
but i solve it by increasing the amount of memory to use for the Java Virtual Machine
run this : weka -m 1024m
You need to specify a classpath after -classpath, similar to the PATH env variable you need to specify the path where Java can find the classes.
The -Xmx500m setting looks fine, except that I would suggest to use 512m.
For Mac OS, you have to edit a configuration file in order to increase the heap size of the Weka UI application.
I am repeating what I wrote in: Is there a workaround to solve "Java heap space" memory error when the max heap value has been already specified?
Quit out of Weka if it is running.
cd into /Applications/weka-XXX.app/Contents , or wherever your weka executable was installed. There will be a file called Info.plist there. It is an XML text file. I suggest you save a copy of it to another location, as you'll need to edit it in the next step.
Open the Info.plist (XML) file in your favorite text editor and look for a block that says "VMOptions". There should be a value that says "-Xmx256M" or something similar that specifies the maximum heap size. You should change that value to something bigger, such as "-Xmx1024M".
Start Weka.
I am running Weka 3.6 in windows. This is what i did.
Go to the Weka installation directory and you will find a RunWeka.bat file. Open this file in a text editor and add -Xmx argument in the java command line.
for instance this sets to 4GB memory,
%_java% -Xmx4096m -classpath . RunWeka -i .\RunWeka.ini -w .\weka.jar -c %_cmd% "%2"
The official Weka answer is right..But....crucial is to first get rid of all JVM files and install the relevant 32 or 64 bit Java version. Not using the relevant version causes many problems including the impossibility to increase the heap further than 1024m (by changing the ini file).
Weka 3.9.2 also does not has the option of maxheap anymore. RunWeka.ini have the option of javaOpts, So you may change the below to your required memory allocation,
javaOpts=%JAVA_OPTS% ---- > javaOpts= -Xmx1024m
Here 1024m is the customised amount of memory you want to allocate.
The best way to do it using this command
java -Xmx1024m -[weka classifier] -t [training file path]
The answers above are too old (last one is 1 year ago).
I had same issue with my WEKA (version 3.8.1) on Windows 10.
I had a problem to update the heap size , the way I fixed it is by adding an environment variable (under control panel) as follows:
JAVA_OPTS = -Xms30000m -Xmx30000m
Tip: Just ensure that RunWeka.ini is using this environment variable.
In the above example I give WEKA 30GB. It works.
Hope it will be helpful for some people.
You should also see if default thread stack size 20MB is enough. Increase the value to 50MB in the file /Applications/weka-3-8-1-oracle-jvm.app/Contents/Info.plist (on MAC) like below:
<string>-Xss50M</string>
If we are using Weka Workbench CLI or Knowledge explorer we need to
change as below.
As the documentation suggests the runtime parameter should be -Xmx[size_required]m where [size_required] is memory size you intend to keep to avoid memory exception.
Open RunWeka.ini
Define maxheap=[size_required]G
In my case I kept maxheap=4G , One can set like maxheap=4096m and add -Xmx#maxheap# to all the run options at # setups (prefixed with "cmd_") sections next to java commands
like below
cmd_default=javaw -Xmx#maxheap# ...............
cmd_console=cmd.exe /K start cmd.exe ..................
cmd_explorer=java -Xmx#maxheap# .................
cmd_knowledgeFlow=java -Xmx#maxheap#....................
maxheap=4G
Verify the same by restarting Weka and Help>>SystemInfo
If you run weka from the command line but not through java i.e. typing weka into the command line, instead of typing
weka
specify the memory flag
weka -m 1024m
This will specify 1024 megabytes.
If you're running weka via weka.sh, you can directly run it with memory option.
For example,
sh weka.sh -memory 10g
This will increase the heap size to 10Gb (tested using Weka 3.8.4 on Ubuntu 18.04)

Netbeans Module Development out of memory

I am creating a module in netbeans to help with a project i am working on however when I run the module in the developmental IDE i get an out of memory exception while loading an asset. This procedure seems to work fine in the base netbeans environment but when i make the same calls during module development i get the error. After attempting to load the asset in several differnt ways i tried appending the following to project.properties and then to Netbeans Platform config(platform.properties)
netbeans_default_options="-J-Xms384m -J-Xmx1024m -J-XX:PermSize=32m -J-XX:MaxPermSize=96m -J-Xverify:none"
and also tried
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"
I have also tried
test.run.args=-ea -Xms1024m -Xmx1024m
I was stuck in this issue for a while. Adding this line into project.properties has solved the problem:
run.args.extra=-J-Xms128m -J-Xmx512m -J-XX:MaxPermSize=512m
While it improved the heap memory size, apparently the problem was gone because of the increased non-heap memory size (J-XX:MaxPermSize=512m).
Good luck
If the problem occurs when you install your module in the development IDE, you can configure the maximum heap size and perm size in <netbeans-install-dir>/etc/netbeans.conf by appending your -J-Xmx and -J-XX:MaxPermSize parameters to the netbeans_default_options variable. You should also append -J-XX:+UseConcMarkSweepGC -J-XX:+CMSClassUnloadingEnabled -J-XX:+CMSPermGenSweepingEnabled, as noted in the docs (see http://wiki.netbeans.org/FaqGCPauses).
Had a similar memory problem on my Linux Debian.
Only Works on linux / possibly UNIX OS's???
Here is how to fix it:
run a terminal
log in as root
type crontab -e
scroll to the bottom or the file and type * * * * * sync; echo 3 > /proc/sys/vm/drop_caches
This magic line cleared all unused ram every minute. It removed the unused memory NetBeans was producing (including any other memory-consuming programs).
plz tell me if this works.
solution to Out of memory exception in netbeans is![.....][1]
I have tried by setting project properties.
right click on project --> select Properties-->General Settings-->VM Options
Add below parameters -Xms256m -Xmx512m

How to increase heap size for jBoss server

I have an upload files scenario in my project. When I'm trying to upload the large files it's giving me an OutOfMemory error. That error is related to Java heap size.
How can you increase the heap size in Java and which file do I need to alter for this? I'm using jboss 5.1 server for running my application.
You can set it as JVM arguments the usual way, e.g. -Xms1024m -Xmx2048m for a minimum heap of 1GB and maximum heap of 2GB. JBoss will use the JAVA_OPTS environment variable to include additional JVM arguments, you could specify it in the /bin/run.conf.bat file:
set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m"
However, this is more a workaround than a real solution. If multiple users concurrently uploads big files, you'll hit the same problem sooner or later. You would need to keep increasing memory for nothing. You should rather configure your file upload parser to store the uploaded file on temp disk instead of entirely in memory. As long as it's unclear which parser you're using, no suitable answer can be given. However, more than often Apache Commons FileUpload is used under the covers, you should then read the documentation with "threshold size" as keyword to configure the memory limit for uploaded files. When the file size is beyond the threshold, it would then be written to disk.
On wildfly 8 and later, go to /bin/standalone.conf and put your JAVA_OPTS there, with all you need.
Edit the following entry in the run.conf file. But if you have multiple JVMs running on the same JBoss, you might want to run it via command line argument of -Xms2g -Xmx4g (or whatever your preferred start/max memory settings are.
if [ "x$JAVA_OPTS" = "x" ]; then
JAVA_OPTS="-Xms2g -Xmx4g -XX:MaxPermSize=256m -Dorg.jboss.resolver.warning=true
Use -Xms and -Xmx command line options when runing java:
-Xms<size> set initial Java heap size
-Xmx<size> set maximum Java heap size
For more help type java -X in command line.
I have mentioned the configuration changes needed for the increase of heap size in Windows or Linux environments.
Linux:
bin/standalone.conf
Check for the following line,
JAVA_OPTS
and change it accordingly to suit your heap size needs
-Xms1303m: initial heap size in megabytes
-Xmx1303m: maximum heap size in megabytes
JAVA_OPTS="-Xms1024M -Xmx2048M -XX:MaxPermSize=2048M -XX:MaxHeapSize=2048M"
Windows:
bin/standalone.conf.bat
JAVA_OPTS="-Xms1024M -Xmx2048M -XX:MaxPermSize=2048M -XX:MaxHeapSize=2048M"
Now restart the server and it will work without prompting any heap size errors.
For more information you can refer this link below.
https://access.redhat.com/documentation/en-us/jboss_enterprise_application_platform/5/html/getting_started_guide/adjust_memory_settings
Look in your JBoss bin folder for the file run.bat (run.sh on Unix)
look for the line
set JAVA_OPTS, (or just JAVA_OPTS on Unix) at the end of that line add -Xmx512m. Change the number to the amount of memory you want to allocate to JBoss.
If you are using a custom script to start your jboss instance, you can add the set JAVA_OPTS option there as well.
In my case, for jboss 6.3 I had to change JAVA_OPTS in file jboss-eap-6.3\bin\standalone.conf.bat and set following values -Xmx8g -Xms8g -Xmn3080m for jvm to take 8gb space.
Add following option in jboss in bin/standalone.conf.bat
set "JAVA_OPTS=-Xms1G -Xmx1G -XX:MetaspaceSize=96M -XX:MaxMetaspaceSize=1024m"
What to change?
set "JAVA_OPTS=%JAVA_OPTS% -Xms1024m -Xmx2048m"
Where to change? (Normally)
bin/standalone.conf(Linux) standalone.conf.bat(Windows)
What if you are using custom script which overrides the existing settings? then?
setAppServerEnvironment.cmd/.sh (kind of file name will be there)
More information are already provided by one of our committee members!
BalusC.
You can increase or set the heap size configuration i.e. -Xms/Xmx or any other JVM options in the JBoss application server in JAVA_OPTS JVM options in standalone.conf(Linux) & standalone.conf.bat file in Windows.
JAVA_OPTS="-Xms2048M -Xmx2048M"

Categories