Help setting up Java VM size - java

Well I am very new to Java and can't understand how am I supposed to set the virtual machine's size. I've built a small web applet that displays images. Sometimes the images can be pretty large, when this happens I get:
*Exception in thread "Image Fetcher 0" java.lang.OutOfMemoryError: Java heap space*
I've been trying to follow different instructions that I found on the Internet and have finally created this shortcut to Eclipse with the following command-line:
"C:\Documents and Settings\Dror Well\Desktop\temp\Eclipse\eclipse\eclipse\eclipse.exe"
-vmargs -vm "C:\Program Files\Java\jdk1.6.0_14\bin"
\"C:\Program Files\Java\jre6\bin\javaw.exe" -Xms256m -Xmx1024m
What am I missing? How should this be done?

In that line you have set the VM args to the Java process that Eclipse runs in. What you need to do for your application is to set the -Xmx512m (or however big you want it to be) for the application that you are running. You can do this from the Run dialog.
From the Run menu, choose 'Open Run Dialog'. In there, you should see on the left side a list of programs. If you have run it once already, yours should be listed in the Java Applications node. Select it and on the right panel, go to the Arguments tab. There will be a VM Arguments text box. Enter your -Xmx arg there.

The parameters should be passed to the JVM running your application, not the one running Eclipse. Try looking through the debug settings in Eclipse, there should be some place to put the -Xmx and -Xms parameters.

Since the images can be pretty large, you should look at the following alternatives:
Allocate more memory to the Java executable that will be launched by Eclipse (not Eclipse itself). This can be done via the VM arguments for the runtime configuration that you use to run the application in Eclipse.
Switch to the parallel garbage collector, using the -XX:+UseParallelGC flag for the application (again, this is not for Eclipse). This wont help if you have large objects retained in memory for a long period of time.

For Eclipse you need to update the eclipse.ini file in order to set any JVM properties. Full details on where the file is and how to update it this link.

Related

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space on eclipse

I am trying to execute this program using fork and join framework. When I feed a JPEG image of smaller size to this program it works fine, but when I give the image of size more than 4 MB it throws below exception:
****Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at ForkBlur.blur(ForkBlur.java:120)
at ForkBlur.main(ForkBlur.java:110)****
I am using eclipse Helios IDE.
I want it to work for larger images of size more than 50 MB
It worked fine for me .
Right click on project which you want to run . Run As -> Run configuration ->Arguments .
Then in VM arguments:
-Xmx1g
You'll need to tell the JVM to allow for more memory for your program. If running the program from the command line, you would use the -mx option to specify how much memory the JVM is allowed to use.
For example, to allow for 128MB of memory, you would do:
java -mx128M MyClass
If running from Eclipse Helios, do this:
Right click on the project and go to properties.
Click on Run/Debug Settings.
Choose your run configuration and click Edit or click New to create one using the Java Application configuration type.
On the Arguments tab, put -mx128M in the VM arguments box.
You need to specify a bigger heap size when you run the program.
You can do it via eclipse if that's your preferred tool. You can right click on the file containing the main method, choose the option "Run As" - this would open up a dialog where you can set up host of command line options (look for arguments section).
The command line option to configure the maximum heap size is Xmx; an example would be Xmx 2g to set the maximum heap size to 2 gb.

Location of Java dump heap file when using jconsole?

Well this is embarrassing ...
I'm starting to play with the Eclipse Memory Analyzer to look for Java memory leaks on a Windows box. Step 1 is to obtain a heap dump file. To do this I start my Java (javaw.exe) process from within Eclipse and connect to it with jconsole. Then on the jconsole MBeans tab I click the dumpHeap button. The first time I did this, I saw a pop-up saying it had created the heap dump file, but not giving its name or location. Now whenever I do a dumpHeap again while connected to a different javaw.exe process, jconsole says:
Problem invoking dumpHeap : java.io.IOException: File exists
and of course doesn't give its name or path. Where could it be?
I've searched my C: drive (using cygwin command line tools) for files containing "hprof" or "java_pid" or "heapdump" and didn't find anything plausible. I've even used the Windows search to look for all files in my Eclipse workspace that have changed in the last day.
I'm using the Sun Java 1.6 JVM, and don't have -XX:HeapDumpPath set.
Update (28 April 2010): My original heap file location must have been determined by jconsole, the tool I triggered the heap dump from. The JVM's heap dump location must apply only to heap dumps it triggers (eg, on an OutOfMemoryException).
Matt B's suggestion to use jvisualvm nicely solves my problem by pointing me to a far more useful replacement for the old jconsole. It has a nice memory profiler that shows which types of objects are most numerous and hold the most memory. And it has a monitor that shows actual memory use over time. When you ask it for a heap dump, it tells you the file name even! The Eclipse Memory Analyzer gives you full details.
Try jvisualvm, it has a much better interface.
Note that starting with JDK version 6 update 7 or greater, Java VisualVM is bundled with JDK. See here.
According to the docs for the Sun Java SE6 JVM:
By default the heap dump is created in
a file called java_pid<pid>.hprof in the
working directory of the VM
In Eclipse, the working directory is defined on the "Arguments" tab of the "Run Configurations" dialog. The default value is the same directory as the class that you are running.
why don't you set the first parameter for dumpHeap(String,boolean) when you try to invoke dumpHeap() from jconsole? it's the generated heapdump file's location and filename.
You could always use ProcessMonitor to see where it's trying to write to :) Done this myself in the past.
I found the dumped file into the same folder where the .bat file whic launch my java application is placed. (I'm using windows 8.1, java 7)
In my case jboss, /jboss-as/bin/ folder.
To find it I searched * files, with today creation date and more than 200MB.

OutOfMemory in Eclipse in a Launched process

I have an OutOfMemory (heap size) in eclipse using a third party plugin
The plug in is Adobe Livecycle work bench and during the out of memory the
plugin is retrieving via WS (using Axis) a list of around 70 workflow components
on my server
Here is a extract of my call stack in Eclipse
... at org.eclipse.equinox.launcher.Main.main(Main.java:1144)
Caused by: java.lang.OutOfMemoryError: Java heap space; nested
exception is: java.lang.OutOfMemoryError: Java heap space at
org.apache.axis.message.SOAPFaultBuilder.createFault ...
I am using this eclipse.ini
-showlocation
-vm
C:\bea920\jdk150_04\bin\javaw.exe
-vmargs
-Xms512M
-Xmx1024M
I don't use any commandline options
I have added -Xmx1024m to my only Installed JRE in Java/Installed JREs
It seems to me that :
-eclipse is not OutOfMemory itself
it displays only 300Mo out of 1024Mo used
it continues working properly
-the plugin launch its axis parsing without giving it enough memory
Questions :
- Are my suppositions right ?
- How do I find where and how to give more memory to the process launched by eclipse launcher ?
Have you changed your launched VM arguments from the preferences window? Try this:
Window->Preferences
Java->Installed JREs
(select your jre here)->Edit..
Default VM Arguments: -Xmx1024m (or whatever size you like)
Edit 1: Based on your comments, I see that you've already tried this. I assumed that you did not try it based on the portion of your question that reads "How do I find where and how to give more memory to the process launched by eclipse launcher ?". I guess we all know what happens when we assume!
Have you considered upping the memory to something larger just to see if you can get it to run (and possibly get some more info about what is causing it to crash)? Try -Xmx2048m or larger depending on your available memory.
Can you add some information to your question that gives us an idea of what the plugin does? Is this project a web service? etc..
See if you are passing Xms and Xmx options in the command line that you are running eclipse with. The values there will override the values in the eclipse.ini
I think you need to edit your eclipse.ini file which is located in the
same directory as your eclipse exe file. It will contain the -Xms settings
which you can then change.
I recommend running eclipse with the -clean option to purge any caches and re-read your settings.
Also, I've had success moving the eclipse.ini out of the eclipse directory (so there's no eclipse.ini), running eclipse, exiting, moving the ini file back and running again. I didn't bother to try to understand why that helped.
Add -XX:MaxPermSize=256m
This is yet-another-memory-type in Java.
I was able to find were the problem is
I used Fiddler with eclipse (using proxy settings)
This way I was able to spot that the soap answer was an OutOfMemory
soapenv:Fault
faultcode soapenv:Server.generalException
faultstring java.lang.OutOfMemoryError: Java heap space; nested exception is:
java.lang.OutOfMemoryError: Java heap space
So the problem was on the server
I have now another problem : the server builds an answer which is to big for eclipse
Thank you for your answers

java.lang.OutOfMemoryError: Java heap space with NetBeans

This is the error I get when I run my web application in an instance of the Tomcat servlet container started by NetBeans. To fix this I even changed the heap size in netbeans.conf, but still it shows the same error. How can I keep this from happening?
HTTP Status 500 -
--------------------------------------------------------------------------------
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Servlet execution threw an exception
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:362)
root cause
java.lang.OutOfMemoryError: Java heap space
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.
Changing the heap size in netbeans.conf only changes the heap for NetBeans itself, not for applications run through NetBeans.
The correct way is to right-click on the project and select "Properties" and then "Run"; there you can set the VM options appropriately (-Xmx256m, for instance). It should look something like this:
(Thanks to VonC for finding this picture.)
Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used. For example,
set CATALINA_OPTS="-Xms512m -Xmx512m" (Windows)export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
In catalina.bat or catallina.sh, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options.
What is the difference between CATALINA_OPTS and JAVA_OPTS?
The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don't want Tomcat to inadvertently pick up the JVM options intended for other apps. I prefer to use CATALINA_OPTS.
How to set java heap size in JBoss?
Stop JBoss server, edit $JBOSS_HOME/bin/run.conf, and then restart JBoss server. You can change the line with JAVA_OPTS to something like:
JAVA_OPTS="-server -Xms128m -Xmx128m"
How to set java heap size in Eclipse?
You have 2 options:
Edit eclipse-home/eclipse.ini to be something like the following and
restart Eclipse.
-vmargs-Xms64m-Xmx256m
Or, you can just run eclipse command with additional options at the
very end. Anything after -vmargs will be treated as JVM options and
passed directly to the JVM. JVM options specified in the command
line this way will always override those in eclipse.ini. For
example,
eclipse -vmargs -Xms64m -Xmx256m
How to set java heap size in NetBeans?
Exit NetBeans, edit the file netbeans-install/etc/netbeans.conf. For example,
netbeans_default_options="-J-Xms512m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Xverify:none
How to set java heap size in Apache Ant?
Set environment variable ANT_OPTS. Look at the file $ANT_HOME/bin/ant or %ANT_HOME%\bin\ant.bat, for how this variable is used by Ant runtime.
set ANT_OPTS="-Xms512m -Xmx512m" (Windows)export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
If you increase the virtual memory of your Tomcat server then it will be OK.
Steps:
In NB go through the windows menu and add Services
You will find Tomcat in the services. Right click on Tomcat server and select Properties
Go to the platform in the properties and write -Xms512m in VM options field
I'm guessing that increasing the memory won't fix the problem. What is that MonitorFilter doing? What's eating up all that memory?
Your best bet is to figure that out. If this is a web app, see if you can turn off that filter and run without it. If you have success, you know that the MonitorFilter is causing your to fail.
This has nothing to do with NetBeans (well, perhaps), rather it has to do with Tomcat. Tomcat is the process that is running out of heap, not NetBeans. Track down the startup process for your Tomcat. If it's bundled with NB, then Tomcat is buried within the NB installation, check for an "enterpriseN" directory, N being a number, Tomcat is probably in there and it's a rather generic distribution of it.
As to why the monitor is run OOM, that's hard to say, it's a pretty simple process when you think about it. You can also try disabling HTTP monitoring to see if it's a problem with the Monitoring itself or something with your application.

Is there a way to increase virtual memory in an application started from NetBeans?

In my project I often encounter Java heap space errors, i.e., there isn't enough space to run the program any more. Is there any way I can increase virtual memory?
I am not using the command-line. I am using Net Beans.
In NetBeans, you can add command line options using the Properties of the Project, the Run option. There is an option for the JVM command line there. Look at the -Xms and -Xmx options.
This works for JRuby projects as well, incidentally.
Under Netbeans you can set the VM options for a project, in the project properties. Under Properties > Run the last box should be VM Options. Netbeans will use those when running the app.
Java -X, read about java -Xms and -Xmx
Use the command line arguments when invoking JVm as,
java -Xms -Xmx
Running JAR directly is on longer suggested (from Sun) (someone may disagree).
You are suggested to use WebStart/JNLP, applet, or exe/batch wrapper that you can control the startup behaviour of the JVM.
The another way you can do is that implement your own wrapper in Java. i.e. fork the real java.exe with -Xmx in your main() function.

Categories

Resources