Usage:
jmap [option]
(to connect to running process)
jmap [option]
(to connect to a core file)
jmap [option] [server_id@]
(to connect to remote debug server)
where
is one of:
to print same info as Solaris pmap
-heap to print java heap summary
-histo[:live] to print histogram of java object heap; if the "live"
suboption is specified, only count live objects
-clstats to print class loader statistics
-finalizerinfo to print information on objects awaiting finalization
-dump: to dump java heap in hprof binary format
dump-options:
live dump only live objects; if not specified,
all objects in the heap are dumped.
format=b binary format
file= dump heap to
Example: jmap -dump:live,format=b,file=heap.bin
-F force. Use with -dump: or -histo
to force a heap dump or histogram when does not
respond. The "live" suboption is not supported
in this mode.
-h | -help to print this help message
-J to pass directly to the runtime system
$ jhat -help
Usage: jhat [-stack ] [-refs ] [-port ] [-baseline ] [-debug ] [-version] [-h|-help]
-J Pass directly to the runtime system. For
example, -J-mx512m to use a maximum heap size of 512MB
-stack false: Turn off tracking object allocation call stack.
-refs false: Turn off tracking of references to objects
-port : Set the port for the HTTP server. Defaults to 7000
-exclude : Specify a file that lists data members that should
be excluded from the reachableFrom query.
-baseline : Specify a baseline object dump. Objects in
both heap dumps with the same ID and same class will
be marked as not being "new".
-debug : Set debug level.
0: No debug output
1: Debug hprof file parsing
2: Debug hprof file parsing, no server
-version Report version number
-h|-help Print this help and exit
The file to read
For a dump file that contains multiple heap dumps,
you may specify which dump in the file
by appending "#" to the file name, i.e. "foo.hprof#3".
All boolean options default to "true"
jstack:Java堆栈跟踪工具
jstack(Stack Trace for Java):用于生成虚拟机当前时刻的线程快照(一般称为threaddump或者javacore文件)。线程快照就是当前虚拟机内每一条线程正在执行的方法堆栈的集合,生成线程快照的主要目的是定位线程出现长时间停顿的原因,如线程间死锁、死循环、请求外部资源导致的长时间等待等都是导致线程长时间停顿的常见原因。线程出现停顿的时候通过jstack来查看各个线程的调用堆栈,就可以知道没有响应的线程到底在后台做些什么事情,或者等待着什么资源。
命令格式:
$ jstack -help
Usage:
jstack [-l]
(to connect to running process)
jstack -F [-m] [-l]
(to connect to a hung process)
jstack [-m] [-l]
(to connect to a core file)
jstack [-m] [-l] [server_id@]
(to connect to a remote debug server)
Options:
-F to force a thread dump. Use when jstack does not respond (process is hung)
-m to print both java and native frames (mixed mode)
-l long listing. Prints additional information about locks
-h or -help to print this help message
option参数:
-F:当正常输出请求不被响应时,强制输出线程堆栈。
-l:除堆栈外,显示关于锁的附加信息。
-m:如果调用到本地方法的话,可以显示C/C++的堆栈。
示例:
$ jstack -l 8940
2018-12-04 15:50:27
Full thread dump Java HotSpot(TM) 64-Bit Server VM (25.172-b11 mixed mode):
"NettythreadDeathWatcher-2-1" #14 daemon prio=1 os_prio=-2 tid=0x00000000591e6000 nid=0x1e30 waiting on condition [0x000000005b16f000]
java.lang.Thread.State: TIMED_WAITING (sleeping)
at java.lang.Thread.sleep(Native Method)
at io.netty.util.ThreadDeathWatcher$Watcher.run(ThreadDeathWatcher.java:152)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
at java.lang.Thread.run(Thread.java:748)
Locked ownable synchronizers:
- None
... ...
"VM Thread" os_prio=2 tid=0x0000000054e84000 nid=0x37ac runnable
"GC task thread#0 (ParallelGC)" os_prio=0 tid=0x0000000002a03800 nid=0x4200 runnable
"GC task thread#1 (ParallelGC)" os_prio=0 tid=0x0000000002a05000 nid=0x3b48 runnable
"GC task thread#2 (ParallelGC)" os_prio=0 tid=0x0000000002a07000 nid=0x3a90 runnable
"GC task thread#3 (ParallelGC)" os_prio=0 tid=0x0000000002a08800 nid=0x2654 runnable
"VM Periodic Task Thread" os_prio=2 tid=0x00000000563c2800 nid=0x4208 waiting on condition
JNI global references: 255
Given a sorted linked list, delete all duplicates such that each element appear only once.
For example,Given 1->1->2, return 1->2.Given 1->1->2->3->3, return&
在JDK1.5之前的单例实现方式有两种(懒汉式和饿汉式并无设计上的区别故看做一种),两者同是私有构
造器,导出静态成员变量,以便调用者访问。
第一种
package singleton;
public class Singleton {
//导出全局成员
public final static Singleton INSTANCE = new S