views:

311

answers:

4

Hello, I've got problem with java jar files and memory.

I use netbeans 6.7 to develop an application and this application need more memory to run because it converts another files. Whenever this application convert a 6-10 mb file, it'll crash. So I set netbeans VM Options : -Xms32m -Xmx256m and the application can convert 6-10mb files with no problem.

I Clean and Build the project so it can make a jar file of my application. I run the jar on my computer and use jconsole to monitor the memory. The maximum memory to use by the application shows 256 mb. But whenever I move it to some other computers, it shows 65-66 mb on jconsole and the application will crash when convert 6-10 mb files. So I need to use command prompt : java -jar -Xmx256m myjar.jar to execute the jar with maximum memory

Why it can be happen, in my computer the maximum memory shows 256 mb but on another computer 65-66 mb? Can I force another computer to give extra maximum memory to my application?

Thank you for your answer. I'm sorry for my inadequate English. If you all find my question is hard to understand, please let me know.

Best Regards

Denny

ps: fyi the computer i used to develop the application have 2gb ram, on the other computers i tested have 1-2 gb ram.

+5  A: 

You answered your own question. The application must be launched with the -Xmx option.

Yann Ramin
Thank you for your answer. Is it possible to do that automatically? Because i already set the -Xmx option in netbeans. It works on my computer (jconsole shows max memory 256mb) but didn't in other computers (jconsole shows max memory 65-66mb).
Denny
@Denny: I don't think that you can put this information in the jar. You have to write a separate .bat or .sh files to run your program.
tulskiy
@tulskiy Thank you for your answer. Yeah, I've already make a run.bat file just in case I don't find the answer. It works (jconsole shows max memory 256mb when I tested the application on other computers), but that way will show a command prompt. Can I hide it?
Denny
A: 

IIRC, the client VM used to default to 64MB heap. You have to use -Xmx or perhaps generate a launcher for your jar.

Dmitry Leskov
Thank you for your answer. I already set -Xmx in netbeans, but it only works on my computer. I will look for the answer at link you provide, thank you.
Denny
A: 

Configure the settings in 'Run Application' properties with amount of memory that you are expecting in NetBeans IDE.

Phani
Thank you for your answer. If 'Run Application' is the netbeans project properties 'Run', I already did that. It works on my computer but at another computer it seems didn't have any effect.
Denny
Please check whether the properties that you set while running the application is preserved when you moved the same to another computer.
Phani
+1  A: 

I've found alternative, we can use : set _JAVA_OPTIONS=-Xms64m -Xmx128m in command prompt. It makes: java -Xms64m -Xmx128m become default heap memory size. I've got it here.

This way give a satisfied result for me. But if you have better way, please don't hesitate to post it. Anyway, thank you for your responses.

Denny