Java PreparedStatement solution for Memory leakage, preparedstatement
Recently I used java to write a database program and found that memory overflow always occurs after a period of operation. I want to use the memory monitoring tool to check the memory leakage. So I checked it online and saw the jmap tool.
Jmap Tool
Jmap prints out all the 'objects' in the memory of a java Process (using pid) (for example, those objects and their quantity ).
Tools that can output all objects in the memory, or even heap in the VM, can be output in binary to text. Use jmap-histo pid. If you use SHELL jmap-histo pid> a. log, you can save it to the text. After a period of time, you can use the text comparison tool to compare which objects are recycled by GC. Jmap-dump: format = B, file = outfile 3024 can output the heap Memory of the 3024 process to the outfile file, and then work 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) to visually display problems with the current memory in the form of images.
Use the following method on a 64-bit machine:
jmap -J-d64 -heap pid
Command Format
SYNOPSIS
Jmap [option] pid
Jmap [option] executable core
Jmap [option] [server-id @] remote-hostname-or-IP
Parameter description
1) options:
Executable Java executable from which the core dump was produced.
(It may be a java executable program that generates core dump)
Core dump file where information will be printed
Remote-hostname-or-IP remote debug service host name or ip address
The unique server-id. If Multiple Remote debug services exist on one host
2) Basic parameters:
-Dump: [live,] format = B, file = <filename> use the hprof binary format to output the jvm heap content to the file =. the live sub-option is optional. If the live option is specified, only the live object is output to the file.
-Finalizerinfo: prints the information of the object awaiting recycling.
-Heap: displays the heap summary, GC algorithm, heap configuration, and wise heap usage.
-Histo [: live]: prints the number of instances of each class, memory usage, and full name information of the class. the prefix "*" is added at the beginning of the VM internal class name "*". if the live sub-parameter is added, only the number of live objects is counted.
-Permstat: prints information about the persistent layer of classload and jvm heap. contains the name, activity, address, parent classloader, and number of loaded classes for each classloader. in addition, the number of internal strings and the amount of memory occupied are printed.
-F force. Use the-dump or-histo parameter when the pid does not have a corresponding value. In this mode, the live subparameter is invalid.
-H |-help: print the auxiliary information
-J: Pass the parameter to the jvm started by jmap.
The id of the java Process whose pid needs to be printed with the matching information. What is the difference between start-up and work-blog preview? You can use jps to check the information.
I used jmap-histo pid to check which objects in the java program have exceeded memory, and then review the code of the objects that cause memory overflow.
Refer: