Willem van Doesburg
Willem van Doesburg

Reputation: 534

How do I keep memory used by JVM under control?

problem I'm writing a data processing app in java for my raspberry-pi. I'm using postgresql, hibernate and tomcat. My app is designed for minimal memory usage (because of the limitations of the raspberry-pi) but java is claiming all memory. How can i instruct the JVM to use ONLY the memory required.

algorithm To prcess each data item I take the following steps: - retrieve object from table (reference object) - for each object in the table: -- retrieve the object -- compare to reference if test is valid store new object in a second table -- destroy objects

The JVM by default is not releasing memory but claiming more and more memory progressively.

question What JVM options can I use? And What programming stratgies can I use?

Upvotes: 1

Views: 1050

Answers (3)

Joao Polo
Joao Polo

Reputation: 2163

please configure flag -Xmx with maximal memory what you want do allow to jvm.

ex:

java -Xmx256m ...

to allow only 256 mega of memory

If you use a server, like tomcat, jboss, define -Xmx on specific configuration file

Upvotes: 1

Harald
Harald

Reputation: 5103

You can control the heap-size with -Xmx as a JVM option. Further I would guess that postgresql and hibernate are memory hogs. You could try with derby and empired-db or plain old JDBC, depending on the complexity of your app. Myself I have a tomcat 7 running on raspberry pi to digitize some sensor data and serve plots. With ps it claims an RSS of only 50 MB.

USER      PID    VSZ   RSS ST %CPU %MEM     TIME CMD
pi      19633 257988 50040 Sl  0.2 10.0 00:29:32 java -cp WEB-INF/classes:libs/tomcat-embed-core-7.0.37.jar:libs/tomcat-embed-logging-juli-7.0.37.jar:libs/raytion-commons-web.jar:libs/commons-exec-1.1.jar:libs/commons-cli-1.2.jar:libs/commons-lang-3.0.jar:libs/tomcat-embed-logging-log4j-7.0.37.jar:libs/log4j-1.2.16.jar:libs/joda-time-2.3.jar:libs/tomcat-embed-jasper-7.0.37.jar: -Ddatadir=../Heizungsdaten server.WebServer

Upvotes: 2

vahid
vahid

Reputation: 456

"Java VisualVM can allow developers to generate and analyse heap dumps, track down memory leaks, perform and monitor garbage collection, and perform lightweight memory and CPU profiling". That tool is great. You try that. http://docs.oracle.com/javase/6/docs/technotes/tools/share/jvisualvm.html

Upvotes: 0

Related Questions