Java JVM memory tuning
JDK:java Development Kit
Jre:java Runtime environment, run the Java program you write
JVM:java virtual machine,. class file running on virtual machine
How to choose the right Java virtual machine
" Choose a stable jdk(with new, new features)
"" according to the platform and application, select the appropriate vendor JDK. HP- UX can only choose the jdk,aix only IBM jdk;windows ,linux can choose SUN Jdk;solaris platform best to use SUN JDK; Open Source JDK , very little is being used in the production environment
"" 32bit or 64bit
"" memory requirements are small, CPU- Intensive Applications Select 32bit
"" Big Memory application is selected 64bit(breakthrough 4G memory limit, throughput slightly higher)
Java Memory
"" Java memory = heap memory + non-heap memory
"" heap memory = Young generation + old generation -xms ( min )-xmx ( max .)
"" Non-heap memory = Permanent generation + other -xx:pemsize-xx:maxpermsise
The JVM in the latest java8 has removed the permanent generation, replacing it with the metaspace meta-space
Typical memory problems
"" OOM VS ML
"" OOM Memory Overflow, is the program when requesting memory, there is not enough memory for its use
"" ML memory leak, refers to the program after the application of memory, unable to free the requested memory space, resulting in this memory has been occupied
" The final performance is basically the same, usually memory leaks ML will eventually cause an OOM error. In practical applications do not too tangled or draw a distinction, each phenomenon is related.
What is the area where memory problems often occur
"Heap heap memory and pemanent area
"" JVM process Memory and third-party local code used by Java
Like what:
"" Java heap has insufficient memory to allocate new objects or blocks of memory
"" Java heap is full of memory, but s0,s1,eden,old area distribution unreasonable
How to prevent memory-related problems
System aspects:
"," "Enough physical memory
"The Best heap settings
"" is stable OS,jdk , etc.
"" The appropriate garbage collection algorithm strategy
Code aspects:
" don't put a lot of objects into the session . "
the resources that have been exhausted must be released, for example IO,file,jdbc
"" do not violate the specifications of the Java EE
"" reasonable amount of data obtained from the database (can be taken from the cache from the cache)
"" Good Code Habits
Java JVM Memory tuning (from Xiao Qiang public class)