A workaround for memory leaks in Java PreparedStatement

Source: Internet
Author: User

Recently wrote a database program in Java, found that after a period of time after running a memory overflow. Want to use memory monitoring tool to see where the memory leaks, and then surf the internet and see the Jmap tools.


Jmap Tools

Jmap prints out all the ' objects ' in the memory of a Java process (using PID), such as generating those objects and their number.

A tool that can output all in-memory objects, and even the heap in the VM can be exported as text in binary. Use the method Jmap-histo pid. If you use the shell Jmap-histo Pid>a.log can save it to the text, after a period of time, using the text Comparison tool, you can compare what the GC recycled objects. Jmap-dump:format=b,file=outfile 3024 The memory heap of the 3024 process can be output to the outfile file, and with the Mat (Memory Analysis tool), use see: http ://blog.csdn.net/fenglibing/archive/2011/04/02/6298326.aspx) or with Jhat (Java Heap analysis Tool), The ability to visually display current memory in the form of an image is problematic.


The use of 64-bit machines requires the following methods:

Jmap-j-d64-heap PID


command Format

Synopsis

jmap [option] pid

jmap [option] executable core

jmap [option] [[Email Protected]]remote-hostname-or-ip


parameter Description

1) Options:

Executable Java executable from which, the core dump was produced.

(Probably the Java executable that generated the core dump)

Core dump file that will be printed with the information

Remote-hostname-or-ip the host name or IP of the Remote Debug service

Server-id Unique ID, if multiple Remote debug services on a single host

2) Basic parameters:

-dump:[live,]format=b,file=<filename> uses the Hprof binary form to output the JVM's heap content to File =. The live sub-option is optional, and if you specify the live option, only the live object is exported to the file.

-finalizerinfo prints information about objects that are waiting to be reclaimed.

-heap prints the summary of the heap, the algorithm used by the GC, the configuration of the heap, and the use of the wise heap.

-histo[:live] Prints the number of instances per class, memory consumption, class full name information. The internal class name of the VM is prefixed with "*". If the live child parameter is added, only the number of live objects is counted.

-permstat Prints the classload and JVM heap for a long layer of information. Contains the name of each classloader, the liveliness, the address, the parent ClassLoader, and the number of classes loaded. In addition, the number of internal strings and the amount of memory consumed are also printed.

-F coercion. Use the-dump or-histo parameters when the PID is not appropriate. In this mode, the live sub-argument is invalid.

-H | -HELP Printing Auxiliary Information

-j Pass parameters to Jmap-initiated JVM.

The PID needs to be printed with the information of the Java process ID, the difference between entrepreneurship and work-blog preview, you can use JPS to inquire.


I use the Jmap-histo PID to see which objects in the Java program are out of memory and then review the object code that caused the memory overflow.


Reference:
    1. Http://developer.51cto.com/art/201203/321422.htm
    2. Http://developer.51cto.com/art/201203/321461.htm

A workaround for memory leaks in Java PreparedStatement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.