English 中文(简体)
Java 高内存使用率
原标题:Java high memory usage

I have a problem with a Java app. Yesterday, when i deployed it to have a test run, we noticed that our machine started swapping, even though this is not a real monster app, if you know what i mean. Anyway, i checked the results of top and saw that it eats around 100mb of memory (RES in top) I tried to profile memory and check if there is a memory leak, but i couldn t find one. There was an unclosed PreparedStatement, which i fixed, but it didn t mean much. I tried setting the min and max heap size (some said that min heap size is not required), and it didn t make any difference.

这就是我现在的运行方式:

#!/bin/sh

$JAVA_HOME/bin/java -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9025 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -XX:MaxPermSize=40m -Xmx32M -cp ./jarName.jar uk.co.app.App app.properties

这是top 的结果 :

PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+ COMMAND                                                                                                                                                                          
16703 root      20   0  316m 109m 6048 S  0.0 20.8   0:14.80 java   

The thing i don t understand that i configure max PermSize and max Heap size, which add up to 72mb. Which is enough, the app runs well. Why is it eating 109mb of memory still and what is eating it up? It is a 37mb difference, which is quite high ratio. (34%). I don t think this is a memory leak, because max heap size is set and there is no out of memory error, or anything.

One intertesting thing may be that i made a heap dump with VisualVM and then checked it with EclipseMAT and it said that there is a possible leak in a classloader. This is what it says:

The classloader/component "sun.misc.Launcher$AppClassLoader @ 0x87efa40" occupies 9,807,664 (64.90%) bytes. The memory is accumulated in one instance of "short[][]" loaded by "".Keywords sun.misc.Launcher$AppClassLoader @ 0x87efa40

我对此不能做很多,但可能有用。

感谢你提前帮忙

<强 > EDIT

I found this one, maybe there is nothing i can do... Tomcat memory consumption is more than heap + permgen space

问题回答

Javas 内存包括

  • the heap space.
  • the perm gen space
  • thread stack areas.
  • shared libraries, including that of the JVM (will be shared)
  • the direct memory size.
  • the memory mapped file size (will be shared)

可能还有其他的供内部使用。

鉴于37MB的PC内存值约20美分,

Did you try using JConsole to profile the application http://docs.oracle.com/javase/1.5.0/docs/guide/management/jconsole.html Otherwise you can also use JProfiler trial version to profile the application http://www.ej-technologies.com/products/jprofiler/overview.html?gclid=CKbk1p-Ym7ACFQ176wodgzy4YA

然而,检查高内存使用率的第一步应该是检查您是否正在使用应用程序中的对象收藏, 如数组、映射、设置、列表等 。 如果是的话, 那么检查它们是否保留对象的引用( 即使未使用)?





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签