An Overview on Common JVM Level Problems in Java SE Application
来源:互联网 发布:俄罗斯新纳粹 知乎 编辑:程序博客网 时间:2024/06/05 00:46
转载:http://www.blogjava.net/justinchen
Common Problems in Java SE Application
This message is based on the following materials.
http://java.sun.com/developer/technicalArticles/J2SE/monitoring/#Insufficient_Memory
http://java.sun.com/developer/technicalArticles/javase/troubleshoot//
1. Java Memory Basic
1.1 Heap, Non-Heap, and Native
Heap memory is the runtime data area from which memory for all class instances and arrays is allocated.
Non-heap memory includes the method area and memory required for the internal processing or optimization of the JVM.
It stores per-class structures such as a runtime constant pool, fieldand method data, and the code for methods and constructors.
Native memory is the virtual memorymanaged by the operating system. When the memory is insufficient for anapplication to allocate, a java.lang.OutOfMemoryError will be thrown.
1.2 GC and Full GC
The garbage collector (GC) detects garbage, defined as objects that areno longer reachable, then reclaims it and makes space available to therunning program. The GC typically works in a stop-the-world fashion --that is, it freezes the heap when working.
The above diagram describes the layout of HotSpot VM Heap and itconsists of three parts: perm generation, old generation and new/yanggeneration. The perm generation is basically for class loading. Nextare the old and young generation. The young generation is furtherbroken up into three spaces: Eden, Survivor Space 1 (SS#1) and SurvivorSpace 2 (SS#2).
2. Memory Problems: out of memory, memory leak and Frequently full GC
- java.lang.OutOfMemoryError: Java heap space => It indicates that an object could not be allocated in the Java heap.
- Configuration issue, where the specified heap size (or the defaultsize, if not specified) is insufficient for the application.
- The application is unintentionally holding references to objects, andthis prevents the objects from being garbage collected. This is theJava language equivalent of a memory leak.
- One other potential source of OutOfMemoryError arises with applications that make excessive use of finalizers.
- java.lang.OutOfMemoryError: PermGen space => the permanent generation is full.
- Ifan application loads a very large number of classes, then the size ofthe permanent generation might need to be increased using the-XX:MaxPermSize option.
- Interned java.lang.Stringobjects are also stored in the permanent generation.If an applicationinterns a huge number of strings, the permanent generation might needto be increased from its default setting.
- java.lang.OutOfMemoryError: Requested array size exceeds VM limit
attempted to allocate an array that is larger than the heap size - java.lang.OutOfMemoryError: request <size> bytes for <reason>. Out of swap space?
The Java Native Interface (JNI) code or the native library of anapplication and the JVM implementation allocate memory from the nativeheap. An OutOfMemoryError will be thrown when an allocation in thenative heap fails. - java.lang.OutOfMemoryError: <reason> <stack trace> (Native method)
an indication that a native method has encountered an allocationfailure. The difference between this and the previous message is thatthe allocation failure was detected in a JNI or native method ratherthan in Java VM code.
3. Thread Problems: dead lock, infinite loop and high lock contention
- Dead Lock
- blockby object monitor: Each object is associated with a monitor. If athread invokes a synchronized method on an object, that object islocked.
- block by java.util.concurrent.locks
- Looping Thread
Ifthread CPU time is continuously increasing, but it is not unresponsive.An infinite loop may consume all available CPU cycles and cause therest of the application to be unresponsive. - High Lock Contention
Synchronization is heavily used in multithreaded applications to ensuremutually exclusive access to a shared resource or to coordinate andcomplete tasks among multiple threads.
Or too many threads are waiting for a limited resource.
Troubleshooting Tools in Java SE Application
1. Command line tools
NAME
Description
Target Problem
jstat
Java Virtual Machine Statistics Monitoring Tool
JVM memory statistics including memory usage, garbage collection time, class loading, and the just-in-time compiler statistics
jmap
Java Memory Map
It prints shared object memory maps or heap memory details of a given process, core file, or remote debug server. It offers an inclusive, detailed memory configuration and information on free space capacity
jhat
Java Heap Analysis Tool
Parse a binary heap dump, launch a web browser, and present standard queries.
jps
Java Virtual Machine Process Status Tool
The jps tool lists the instrumented HotSpot Java Virtual Machines (JVMs) on the target system. In other words, it lists java application and its process id.
jstack
Java Stack Trace
It provides the stack traces of all the threads attached to a VM, such as application threads and interval VM threads. It also performs deadlock detection and will perform a stack trace if the VM is hung
HPROF
The Heap and CPU Profiling Agent
a heap-CPU profiling tool that collects information on CPU usage, heap dumps, and thread states, uses the JVM Tool Interface (JVMTI), so every JVM has a diagnostic interface
jinfo
Java Configuration Info
jinfo prints Java configuration information for a given Java process or core file or a remote debug server. And it can set java configuration property at runtime.
XX:+HeapDumpOnOutOfMemoryError
When an OutOfMemoryError is thrown, a heap dump file named java_pid<pid>.hprof will be created automatically
2. Visual Tools
NAME
Description
Target Problem
jconsole
Launch a GUI to monitor and manage Java applications and Java VMs on a local or remote machine.
Memory and Thread Problem
jvisualvm
Java Visual VM
Java VisualVM relies on tools such as jstat, jinfo, jstack, and jmap to obtain detailed information about applications running inside a JVM. It then presents the data in a unified, graphically rich manner.
- An Overview on Common JVM Level Problems in Java SE Application
- An overview on domain adaptation in neural machine translation
- Common Beginner Problems in JSF
- Makefiles in Linux: An Overview
- 关于Java SE出现报错Exception in thread "main" java.lang.Error: Unresolved compilation problems...
- Improve Application Performance With SwingWorker in Java SE 6
- Common Memory Management Problems in C++
- Java精华知识点汇总(Most Common Problems in Interview for Java Engineer)
- Using wait(), notify() and notifyAll() in Java: common problems and mistakes
- Deep Learning in Neural Networks: An Overview
- An overview of memory management in QEMU
- common causes of the JEE application performance problems
- Common Problems (and Their Solutions) for java
- Using Theme in an Application
- Using Theme in an Application
- the virtual machine is in use by an application on your host computer
- 虚拟机the virtual machine is in use by an application on your host computer解决
- C++ Gotchas: Avoiding Common Problems in Coding and Design
- 打造完美的xml技术解决方案件(dom4j/xstream)
- mapguide studio破解
- XML::XML XLS之XLST三
- 构建和实现单点登录解决方案
- java反射机制获取成员变量调用和调用实例方法的实现
- An Overview on Common JVM Level Problems in Java SE Application
- 如何通过HtmlInputFile控件上传文件的类
- 用javascript打开模态页面并得到返回值
- GC(Garbage collection) Log and Analysis
- PHP 集成环境之 WampServer2.0
- (转载)CreateRemoteThread (代码注入)
- winform menustrip的遍历
- 指针和堆的内存分配&指针数组和数组指针(转)
- 用Visual C#实现MVC模式的简要方法(转)