package jvm.gcDemos;
public class RebornObj {
public static RebornObj obj;
public static void main(String[] args) throws InterruptedException {
obj = new RebornObj(); // 在堆空间中new一个RebornObj对象,并让元空间的obj指针指向它
obj = null;
System.gc(); // 第一次gc,堆中对象的finalize()方法被调用
System.out.println("第一次gc");
Thread.sleep(2000);
if (obj == null) {
System.out.println("obj is dead");
} else {
System.out.println("obj is still alive");
}
obj = null;
System.gc(); // 第二次gc,堆中对象的finalize()方法不会被调用
System.out.println("第二次gc");
if (obj == null) {
System.out.println("obj is dead");
} else {
System.out.println("obj is still alive");
}
}
@Override
protected void finalize() throws Throwable {
super.finalize();
System.out.println("待回收对象的finalize方法被调用");
obj = this;
}
}
控制台输出
待回收对象的finalize方法被调用
第一次gc
obj is still alive
第二次gc
obj is dead
Process finished with exit code 0
使用MAT进行GC Roots溯源
1)、首先下载MAT,可访问官网https://www.eclipse.org/mat/
下载后直接解压,打开里面的MemoryAnalyzer.exe就能用
2)、编写样例代码
package jvm.gcDemos;
import java.util.ArrayList;
import java.util.Date;
import java.util.Scanner;
public class GCRoots {
public static void main(String[] args) {
ArrayList strings = new ArrayList();
Date date = new Date();
for (int i = 0; i < 100; i++) {
strings.add(String.valueOf(i));
try {
Thread.sleep(30);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
System.out.println("添加数据结束,请指示:");
new Scanner(System.in).next();
strings = null;
date = null;
System.out.println("数据已置空,请结束:");
new Scanner(System.in).next();
System.out.println("结束");
}
}
G1把堆内存分割为很多不相关的区域(Region)(物理上是不连续的),用这些区域来表示伊甸园区、幸存者区、老年代等。它有计划地避免在整个堆中进行全区域的垃圾收集,跟踪各个区域里垃圾堆积的价值大小(回收所得空间大小,以及回收所需时间的经验值),在后台维护一个优先列表,每次根据允许的收集时间,优先回收价值最大的区域。由于这种方式的侧重点在于回收垃圾最大量的区间,所以G1的名字就是Garbage First
{Heap before GC invocations=1 (full 0):
PSYoungGen total 2560K, used 2046K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 99% used [0x00000000ffd00000,0x00000000ffeffac8,0x00000000fff00000)
from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
to space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
ParOldGen total 7168K, used 0K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffd00000)
Metaspace used 2978K, capacity 4494K, committed 4864K, reserved 1056768K
class space used 321K, capacity 386K, committed 512K, reserved 1048576K
2020-05-20T21:20:13.237+0800: 0.202: [GC (Allocation Failure) [PSYoungGen: 2046K->504K(2560K)] 2046K->863K(9728K), 0.0009002 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap after GC invocations=1 (full 0):
PSYoungGen total 2560K, used 504K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000fff00000)
from space 512K, 98% used [0x00000000fff00000,0x00000000fff7e030,0x00000000fff80000)
to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
ParOldGen total 7168K, used 359K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 5% used [0x00000000ff600000,0x00000000ff659ed8,0x00000000ffd00000)
Metaspace used 2978K, capacity 4494K, committed 4864K, reserved 1056768K
class space used 321K, capacity 386K, committed 512K, reserved 1048576K
}
Java HotSpot(TM) 64-Bit Server VM (25.231-b11) for windows-amd64 JRE (1.8.0_231-b11), built on Oct 5 2019 03:11:30 by "java_re" with MS VC++ 10.0 (VS2010)
Memory: 4k page, physical 16624412k(8666512k free), swap 19770140k(7853452k free)
CommandLine flags: -XX:InitialHeapSize=10485760 -XX:MaxHeapSize=10485760 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+PrintStringTableStatistics -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC
{Heap before GC invocations=1 (full 0):
PSYoungGen total 2560K, used 2046K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 99% used [0x00000000ffd00000,0x00000000ffeffac8,0x00000000fff00000)
from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
to space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
ParOldGen total 7168K, used 0K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 0% used [0x00000000ff600000,0x00000000ff600000,0x00000000ffd00000)
Metaspace used 2957K, capacity 4494K, committed 4864K, reserved 1056768K
class space used 320K, capacity 386K, committed 512K, reserved 1048576K
2020-05-20T21:46:52.197+0800: 0.217: [GC (Allocation Failure) [PSYoungGen: 2046K->512K(2560K)] 2046K->881K(9728K), 0.0009109 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap after GC invocations=1 (full 0):
PSYoungGen total 2560K, used 512K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000fff00000)
from space 512K, 100% used [0x00000000fff00000,0x00000000fff80000,0x00000000fff80000)
to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
ParOldGen total 7168K, used 369K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 5% used [0x00000000ff600000,0x00000000ff65c448,0x00000000ffd00000)
Metaspace used 2957K, capacity 4494K, committed 4864K, reserved 1056768K
class space used 320K, capacity 386K, committed 512K, reserved 1048576K
}
{Heap before GC invocations=2 (full 0):
PSYoungGen total 2560K, used 2560K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 100% used [0x00000000ffd00000,0x00000000fff00000,0x00000000fff00000)
from space 512K, 100% used [0x00000000fff00000,0x00000000fff80000,0x00000000fff80000)
to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
ParOldGen total 7168K, used 369K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 5% used [0x00000000ff600000,0x00000000ff65c448,0x00000000ffd00000)
Metaspace used 3235K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 349K, capacity 388K, committed 512K, reserved 1048576K
2020-05-20T21:46:52.206+0800: 0.226: [GC (Allocation Failure) [PSYoungGen: 2560K->496K(2560K)] 2929K->977K(9728K), 0.0013469 secs] [Times: user=0.05 sys=0.00, real=0.00 secs]
Heap after GC invocations=2 (full 0):
PSYoungGen total 2560K, used 496K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000fff00000)
from space 512K, 96% used [0x00000000fff80000,0x00000000ffffc010,0x0000000100000000)
to space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
ParOldGen total 7168K, used 481K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 6% used [0x00000000ff600000,0x00000000ff678448,0x00000000ffd00000)
Metaspace used 3235K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 349K, capacity 388K, committed 512K, reserved 1048576K
}
{Heap before GC invocations=3 (full 0):
PSYoungGen total 2560K, used 2544K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 100% used [0x00000000ffd00000,0x00000000fff00000,0x00000000fff00000)
from space 512K, 96% used [0x00000000fff80000,0x00000000ffffc010,0x0000000100000000)
to space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
ParOldGen total 7168K, used 481K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 6% used [0x00000000ff600000,0x00000000ff678448,0x00000000ffd00000)
Metaspace used 3235K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 349K, capacity 388K, committed 512K, reserved 1048576K
2020-05-20T21:46:52.213+0800: 0.233: [GC (Allocation Failure) [PSYoungGen: 2544K->512K(2560K)] 3025K->1041K(9728K), 0.0015696 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap after GC invocations=3 (full 0):
PSYoungGen total 2560K, used 512K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000fff00000)
from space 512K, 100% used [0x00000000fff00000,0x00000000fff80000,0x00000000fff80000)
to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
ParOldGen total 7168K, used 529K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 7% used [0x00000000ff600000,0x00000000ff6847e0,0x00000000ffd00000)
Metaspace used 3235K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 349K, capacity 388K, committed 512K, reserved 1048576K
}
Heap
PSYoungGen total 2560K, used 2156K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
eden space 2048K, 80% used [0x00000000ffd00000,0x00000000ffe9b0e0,0x00000000fff00000)
from space 512K, 100% used [0x00000000fff00000,0x00000000fff80000,0x00000000fff80000)
to space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
ParOldGen total 7168K, used 529K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
object space 7168K, 7% used [0x00000000ff600000,0x00000000ff6847e0,0x00000000ffd00000)
Metaspace used 3242K, capacity 4496K, committed 4864K, reserved 1056768K
class space used 350K, capacity 388K, committed 512K, reserved 1048576K
//关键字的使用探讨/*访问关键词private 只能在本类中访问public 只能在本工程中访问protected 只能在包中和子类中访问默认的 只能在包中访问*//*final 类 方法 变量 final 类 不能被继承 final 方法 不能被子类覆盖,但可以继承 final 变量 只能有一次赋值,赋值后不能改变 final 不能用来修饰构造方法*///this()
What’s new in Zabbix 2.0?
去年开始使用Zabbix的时候,是1.8.X的版本,今年Zabbix已经跨入了2.0的时代。看了2.0的release notes,和performance相关的有下面几个:
:: Performance improvements::Trigger related da
修改jboss端口
%JBOSS_HOME%\server\{服务实例名}\conf\bindingservice.beans\META-INF\bindings-jboss-beans.xml
中找到
<!-- The ports-default bindings are obtained by taking the base bindin
@echo off
::演示:删除指定路径下指定天数之前(以文件名中包含的日期字符串为准)的文件。
::如果演示结果无误,把del前面的echo去掉,即可实现真正删除。
::本例假设文件名中包含的日期字符串(比如:bak-2009-12-25.log)
rem 指定待删除文件的存放路径
set SrcDir=C:/Test/BatHome
rem 指定天数
set DaysAgo=1
HTML5的video和audio标签是用来在网页中加入视频和音频的标签,在支持html5的浏览器中不需要预先加载Adobe Flash浏览器插件就能轻松快速的播放视频和音频文件。而html5media.js可以在不支持html5的浏览器上使video和audio标签生效。 How to enable <video> and <audio> tags in