7

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 :)

1
  • "...throws an exception "Java heap space" (or something similar)." How....helpful. What's the actual exception thrown? Commented Jun 22, 2010 at 13:43

1 Answer 1

26

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.