开发者

Memory usage of PostgreSQL connection is increasing in execution

I have a webcrawler thar uses a connection pool to connect to database and insert pages.

I saw that the memory usage is increasing while the program executes. I guess that I forgot to close some PreparedStatement or another object of the connection.

I call the connection.close method开发者_JAVA百科, but it only returns the connectin to the database.

There is a way to see if there are opened objects in the connection?


You seem to suggest that your application has a memory leak. To begin debugging, you can use jmap, a utility that comes with the JDK (usually found on the bin directory next to java, javac, javadoc, ...etc). This command will produce a memory map of all objects sitting in your JVM. You can run it over time as your application is running and compare object counts to see if there is any type of object that seems to have a continuously increasing total count, but no reductions (as a result of Garbage Collections).

jmap -heap -histo <PROCESS_ID_OF_YOUR JVM>

If you are indeed not closing your statement objects properly, you will quickly see them bubble up to the top of your stack.

All "closable" objects should be closed in finally blocks to avoid leaving open connections, statements, ...etc lingering in the JVM if an exception is thrown before you get to the close.

note: on windows, these executables have the .exe suffix.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜