how to extend Java Virtual Memory in CentOS? - java

as I wrote on the title, I want to extend Virtual Memory while performing my java code.
currently, I'm writing a code for word Analyzer. In eclipse if there are 1000 number of inputs then it gives 1000 fine outputs. however when I run it from a server, it gives 80% outputs and 20% for null. after that I asked this problem to someone I know and he said it is because of small size of Virtual Memory in the server.
I normally run the java program with .sh file and content of the .sh file is written as below.
export JAVA_HOME="usr/lib/jvm/java-1.6.0-openjdk.x86_64"
PATH=$PATH:JAVA_HOME/jre/bin
export JAVA_HOME
java -cp /home/account/count_con.jar countConversation.countCon_Starter &
and then type "bash .sh file".
Please give me your kind advice for how to run java code with extra Virtual memory size in server(OS:CentOS).
Thank you

after java command set the flag -Xmxsizem
FYI
Xms is initial Java heap size
Xmx is maximum Java heap size
Xss is java thread stack size

Related

JAVA does not work with the same resources on Netbeans Project and JAR file when the compile the code

When I build the Project and run the program on netbeans, it runs perfect and fast enough, yet when I export the jar file and start the program on that it is slow and stuck at the middle of the process.
I track the java resource usage and I found the memory problem.
How can I overcome this problem? I want to use the program same as on the Netbeans. How can I remove the constraint to resource usage of JAVA?
I am sorry, I forgot to tell I tried that. I think heap size is different than what I need. -Xmx and -Xms does not work. They don't change the java.exe or javaw.exe memory usage. I need what the Netbeans do to use more ram.
All pictures shows that the problem clearly.
Netbeans runs the program on java with more ram:
When the process parse and write to excel started it use so much ram:
However, when I start the program on JAR file, process so slow and use limited ram:
At the end of the process (parse and write to excel) it was very slow and after a while it stuck because of the lack of memory space that java allows:
If you are sure that memory limit is the only problem then set the maximum heap size that JVM can use, add -Xmx2G command line parameter to java.exe.
You can read more on -X options here.
Problem solved, but I don't know why JDK 1.8 block the memory usage?
Answer : http://forums.netbeans.org/viewtopic.php?p=167390

Read pdf using java

i have a problem with reading PDF file content in java using itextpdf.jar ,
if i read a small sized(5-15MB) PDF file means its working well, it is possible to read it's contents
but when i read large sized(200MB) PDF file means its showing Run time exception like following
enter code hereException in thread "main" java.lang.OutOfMemoryError: Java heap space
at java.util.Arrays.copyOf(Arrays.java:2786)
at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:94)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.InputStreamToArray(RandomAccessFileOrArray.java:213)
at com.itextpdf.text.pdf.RandomAccessFileOrArray.<init>(RandomAccessFileOrArray.java:203)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:235)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:246)
at general.FileStreamClose.main(FileStreamClose.java:28)
Java Result: 1enter code here
any solution for this , how to increase heap size in tomcat
You can tune your Java Application Runtime settings:
maximize heap size to high value with -Xmx say 500M
tune -XX:MaxHeapFreeRatio and -XX:MinHeapFreeRatio to make sure that the application will not becomes irresponsive when consuming lot of memory when the heap reduces.
to increase heap size for tomcat you'll have to set the evnirenment variable JAVA_OPTS and have it contain the -Xmx option for example -Xmx512m
here is a sample script how you can run tomcat
#echo off
set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_33
set CATALINA_HOME=C:\Program Files\apache-tomcat-7.0
set JAVA_OPTS=-XX:MaxPermSize=128m -Xmx512m -server
call %CATALINA_HOME%\bin\catalina.bat run
for additional info, as far as i know, if your machine is 32 bit increase xmx and xms heap size will limited around 1k++. If you need more than that you need to install java 64 bit (of course in 64 machine and 64 OS).

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.

Java Increase Heap size

I have a java application form which i am accessing records from database,processing it and again updaing the database.
I am doing this by converting my java application to JAR and executing it from command prompt.During testing there are only 20 records
per table in database.For that i am executing the jar as follows to avoid out of memory error,
java -jar -Xmx512m MyApp.jar
If database contains much record(50,000),how to increase the heap size while executing jar or How to increase the heap size dynamically based on needs while executing the jar.
Thanks
The maximal heap size is set before running the program by using the -Xmx option you already used. Based on this information, the JVM will use as much heap size as it needs, up to the given amount. So if your program only needs 1 MB of RAM, the JVM will only use that amount, if it needs 1G and you only gave it 512M, you will get an OutOfMemoryError.
So, basically, you can give your program more heap space if you need to, and the JVM will dynamically adjust the used heap size according to its needs.
Sometimes this is not the intended behavior, and the lower bound for heap size can be set with -Xms. Then the JVM will always reserve a heap of the size between Xms and Xmx.
The maximum is the maximum heap you would need ever not how much it will actually use. It's the point at which you would rather than application crash than keep running. The JVM will dynamically manage the memory used up to this point.
How to increase the heap size dynamically based on needs while executing the jar.
So if you want the JVM to use 256 MB, but you want it to dynamically grow up to 30 GB you would set it like this
java -ms256m -mx30g -jar MyApp.jar
Even the minimum is not guaranteed to be used. The JVM will do minimal effort to keep the memory usage up to this level. A Hello World program will not use 256 MB of heap no matter what you set the minimum to.
-Xmx2048m -XX:-UseGCOverheadLimit
Set this in your VM Arguement.
You can set less memory size in place of 2048
This will increase your max heapSize to 1Gb.
java -Xms256m -Xmx1024m -jar MyApp.jar
where -Xms specifies the initial Java heap size and -Xmx the maximum Java heap size.
Parameters to the JVM must be passed before the -jar part. The reason for that can be seen when we execute "java -version" :
Usage:
java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

Help setting up Java VM size

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.

Categories

Resources