JVM相关

2019-04-02 10:58:32 浏览数 (1)

String inter() 方法

https://blog.csdn.net/soonfly/article/details/70147205

finalize 方法

finalize是Object的protect方法,可以完成一次救赎,注意finalize系统只可以调用一次

代码语言:javascript复制
int val;
public static TestFinalize testFinalize = null;

public TestFinalize(int val) {
    this.val = val;
}

@Override
protected void finalize() throws Throwable {
    super.finalize();
    System.out.println("finalize method executing...");
    testFinalize = this;
}

public static void main(String[] args) throws InterruptedException {
    testFinalize = new TestFinalize(1000);
    testFinalize = null;
    System.gc();
    Thread.sleep(500);
    System.out.println(testFinalize == null);
    if (testFinalize != null) {
        System.out.println(testFinalize.val);
    }

    testFinalize = null;
    System.gc();
    Thread.sleep(500);
    System.out.println(testFinalize == null);
    if (testFinalize != null) {
        System.out.println(testFinalize.val);
    }
}


finalize method executing...
false
1000
true

0 人点赞