Java heap space Xmx Xms parameters ignored - java

I have a .JAR that apparently uses up too much memory, and throws an exception "Java heap space" (or something similar).
So I tried running the .JAR via the CMD like this:
C:\MyFolder>javaw -jar MyJar.jar -Xms64m -Xmx128m
That did not solve the problem. Same error.
Now, when I checked the Processes tab in the windows task manager, I noticed that the process of my jar has a lot less memory than what i asked for (same as running it without the parameters).
Why is it ignoring the parameters?
Also, I think the exception is thrown around the time the process reaches 100mb of memory usage. Is it possible that the GC is trying to free up the memory and that's what causes the problem? Is there any parameter I can set for the GC to prevent that?
Thanks, Malki :)

The Command
javaw -jar MyJar.jar -Xms64m -Xmx128m
will use -Xms... and -Xmx... as parameters to the "main(String[] args)" method.
Parameters to the JVM must be passed before the -jar part:
javaw -Xms64m -Xmx128m -jar MyJar.jar
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)
Where your parameters -Xms... and -Xmx... are options to the JVM.

Related

I got error when trying to set java JVM heap size

I have some code running on AWS device farm, that got java heap out of memory exception. So I tried to run some java JVM heap settings locally to see if that works. Here is what I tried:
set java -Xms262144, I know that is in byte, thus 262144 probably doesn't make sense, as too small, but at least that proves this script is correct in syntax.
C02ZxxxGVCF:util i7xxxx$ java -Xms262144
Error occurred during initialization of VM
Too small initial heap
So next I did increase the size to 268435456 which is 256Mb, but it doesn't seem to take that at all. Please see below output from terminal.
C02ZxxxGVCF:util i7xxxxx$ java -Xms268435456
Usage: java [options] <mainclass> [args...]
(to execute a class)
or java [options] -jar <jarfile> [args...]
(to execute a jar file)
or java [options] -m <module>[/<mainclass>] [args...]
java [options] --module <module>[/<mainclass>] [args...]
(to execute the main class in a module)
or java [options] <sourcefile> [args]
(to execute a single source-file program)
Arguments following the main class, source file, -jar <jarfile>,
-m or --module <module>/<mainclass> are passed as the arguments to
main class.
Any tips please?
As shown in the "Usage", you must specify the Java class name or the jar name.
For example,
java -Xms256m HelloWorld
Here instead of HelloWorld specify your java class name
or
java -Xms256m -jar hello.jar
Here instead of HelloWorld specify your jar name

How to increase jvm memory

I want to alter (increase) java memory limit (JRE on windows pc).
I fount following commands everywhere:
-Xms set initial Java heap size
-Xmx set maximum Java heap size
for example -Xmx1024m.
But my Question is where! do I have to enter this command. Sorry for this beginner question. Normally I do not have any contact to java.
If you are using eclipse and try to run standalone java then use vm argument section in run configuration tab .For tomcat or app server in setenv script file put
set JAVA_OPTS=-Xms1024m -Xmx1024m -XX:PermSize=64m -XX:MaxPermSize=384m
for executable jar
java -Xms1024m -Xmx1024m -jar FILENAME.jar
Those are Arguments for the Virtual Machine that you pass in the command line when you start the app
example:
in the console doing:
java -Xms256m -Xmx1024m HelloWorld
or if you are in eclipse (or any other ide)

Understand cmd command which runs java application

I have the following code in the batch:
"C:/EDI_Module/jre1.8.0_121/bin/java" -Xms2g -Xmx10g -cp .;C:/EDI_Module/jar/;C:/EDI_Module/lib/; com/solverelogistics/edi/MainGenerator
Can you please tell me what is going on here? I know it runs some app. Which one is the java application?
The JRE executable (the bytecode interpreter):
"C:/EDI_Module/jre1.8.0_121/bin/java"
The starting memory size:
-Xms2g
The maximum memory size:
-Xmx10g
The classpath:
-cp .;C:/EDI_Module/jar/;C:/EDI_Module/lib/;
The class containing a public static void main method to execute:
com/solverelogistics/edi/MainGenerator
Note: I would have typically expect the class to look something like this com.solverelogistics.edi.MainGenerator, with ., not /.

How to use the Xmx command? (JVM Heap memory)

I'm new in the Oracle world and I'm working with Oracle Identity Analytics (OIA). In the test environment everything is ok, but in production environment i'm getting an "java.lang.OutOfMemoryError", so when I checked the Xmx and Xms I saw that I had Xmx:512m and Xms:512m, that's why I'm trying to modify the Xmx value.
I want to modify the Xmx and Xms values so I wrote the following line in my PuTTY:
$ java -Xmx1024m
But the PuTTY shows me the following:
Usage: java [-options] class [args...] (to execute a class) or
java [-options] -jar jarfile [args...] (to execute a jar file)
where options include:...
Seems like I'm forgetting something after "Xmx1024m", but what? Well, now I know I'm forgetting Jar file, Class or App name but I have no idea how to get any of those things. I tried putting "$AdminServer" after "Xmx1024m" but it didn't work.
My Java version is 1.6.0_45 Oracle JRockit build R28 and the Operative Systems is Linux Server 6.5.
Regards!
You have to pass filepath to execute. Of course, you can run
java -Xmx1024m
but Java doesn't know what file should be executed
You will have to pass the program-name/filename/jar-name,whatever it is,with path for which you want to set/reset the java heap size.
e.g
java -Xms1024M -Xmx2048M -jar xi.jar
java -Xmx64m ${PROGRAM_NAME}
Hope this helps you.Or to help you better,could you please tell us what exactly is your scenario?

PlayFramework memory setting options are not respected

I have a Play Framework application that I want to run on production mode but whenever I run activator start -mem 512 or activator start -J-Xms512m -J-Xmx512m I get errors about JVM not being able to allocate enough memory. The odd thing is that error logs indicate that arguments passed on to jvm was:
-Xms1024m -Xmx1024m -XX:ReservedCodeCacheSize=128m -Duser.dir=/home/oguz/dev/rhymo-server/target/universal/s$
but when I print the command information from the activator bash script I get:
java -Dactivator.home=/home/oguz/frameworks/activator-1.2.12 -Xms512m -Xmx512m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=256m -jar /home/oguz/frameworks/activator-1.2.12/activator-launch-1.2.12.jar start
It seems that play is running the right command but somewhere along the lines the arguments get discarded. What is wrong here? Am I forgetting something?
I think that you are facing a bug in Activator. You can work around it using JAVA_OPTS:
$ JAVA_OPTS="-Xms512m -Xmx512m -XX:MetaspaceSize=64m" ./activator start
or add an alias to this to your .bashrc/.zshrc. Also you can run activator stage and then start your app using
$ target/universal/stage/bin/YOUR-APP-NAME -mem 512

Categories

Resources