java.lang.ref.Cleaner#Cleanable ( )源码实例Demo

下面列出了java.lang.ref.Cleaner#Cleanable ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-jdk9   文件: CleanerTest.java
/**
 * Create a CleanableCase for a PhantomReference.
 * @param cleaner the cleaner to use
 * @param obj an object or null to create a new Object
 * @return a new CleanableCase preset with the object, cleanup, and semaphore
 */
static CleanableCase setupPhantomSubclassException(Cleaner cleaner, Object obj) {
    if (obj == null) {
        obj = new Object();
    }
    Semaphore s1 = new Semaphore(0);

    Cleaner.Cleanable c1 = new PhantomCleanable<Object>(obj, cleaner) {
        protected void performCleanup() {
            s1.release();
            throw new RuntimeException("Exception thrown to cleaner thread");
        }
    };

    return new CleanableCase(new PhantomReference<>(obj, null), c1, s1, true);
}
 
源代码2 项目: openjdk-jdk9   文件: CleanerTest.java
/**
 * Create a CleanableCase for a WeakReference.
 * @param cleaner the cleaner to use
 * @param obj an object or null to create a new Object
 * @return a new CleanableCase preset with the object, cleanup, and semaphore
 */
static CleanableCase setupWeakSubclassException(Cleaner cleaner, Object obj) {
    if (obj == null) {
        obj = new Object();
    }
    Semaphore s1 = new Semaphore(0);

    Cleaner.Cleanable c1 = new WeakCleanable<Object>(obj, cleaner) {
        protected void performCleanup() {
            s1.release();
            throw new RuntimeException("Exception thrown to cleaner thread");
        }
    };

    return new CleanableCase(new WeakReference<>(obj, null), c1, s1, true);
}
 
源代码3 项目: openjdk-jdk9   文件: CleanerTest.java
/**
 * Create a CleanableCase for a SoftReference.
 * @param cleaner the cleaner to use
 * @param obj an object or null to create a new Object
 * @return a new CleanableCase preset with the object, cleanup, and semaphore
 */
static CleanableCase setupSoftSubclassException(Cleaner cleaner, Object obj) {
    if (obj == null) {
        obj = new Object();
    }
    Semaphore s1 = new Semaphore(0);

    Cleaner.Cleanable c1 = new SoftCleanable<Object>(obj, cleaner) {
        protected void performCleanup() {
            s1.release();
            throw new RuntimeException("Exception thrown to cleaner thread");
        }
    };

    return new CleanableCase(new SoftReference<>(obj, null), c1, s1, true);
}
 
源代码4 项目: openjdk-jdk9   文件: CleanerTest.java
/**
 * Create a CleanableCase for a PhantomReference.
 * @param cleaner the cleaner to use
 * @param obj an object or null to create a new Object
 * @return a new CleanableCase preset with the object, cleanup, and semaphore
 */
static CleanableCase setupPhantom(Cleaner cleaner, Object obj) {
    if (obj == null) {
        obj = new Object();
    }
    Semaphore s1 = new Semaphore(0);
    Cleaner.Cleanable c1 = cleaner.register(obj, () -> s1.release());

    return new CleanableCase(new PhantomReference<>(obj, null), c1, s1);
}
 
源代码5 项目: openjdk-jdk9   文件: CleanerTest.java
/**
 * Create a CleanableCase for a PhantomReference.
 * @param cleaner the cleaner to use
 * @param obj an object or null to create a new Object
 * @return a new CleanableCase preset with the object, cleanup, and semaphore
 */
static CleanableCase setupPhantomSubclass(Cleaner cleaner, Object obj) {
    if (obj == null) {
        obj = new Object();
    }
    Semaphore s1 = new Semaphore(0);

    Cleaner.Cleanable c1 = new PhantomCleanable<Object>(obj, cleaner) {
        protected void performCleanup() {
            s1.release();
        }
    };

    return new CleanableCase(new PhantomReference<>(obj, null), c1, s1);
}
 
源代码6 项目: openjdk-jdk9   文件: CleanerTest.java
/**
 * Create a CleanableCase for a WeakReference.
 * @param cleaner the cleaner to use
 * @param obj an object or null to create a new Object
 * @return a new CleanableCase preset with the object, cleanup, and semaphore
 */
static CleanableCase setupWeakSubclass(Cleaner cleaner, Object obj) {
    if (obj == null) {
        obj = new Object();
    }
    Semaphore s1 = new Semaphore(0);

    Cleaner.Cleanable c1 = new WeakCleanable<Object>(obj, cleaner) {
        protected void performCleanup() {
            s1.release();
        }
    };

    return new CleanableCase(new WeakReference<>(obj, null), c1, s1);
}
 
源代码7 项目: openjdk-jdk9   文件: CleanerTest.java
/**
 * Create a CleanableCase for a SoftReference.
 * @param cleaner the cleaner to use
 * @param obj an object or null to create a new Object
 * @return a new CleanableCase preset with the object, cleanup, and semaphore
 */
static CleanableCase setupSoftSubclass(Cleaner cleaner, Object obj) {
    if (obj == null) {
        obj = new Object();
    }
    Semaphore s1 = new Semaphore(0);

    Cleaner.Cleanable c1 = new SoftCleanable<Object>(obj, cleaner) {
        protected void performCleanup() {
            s1.release();
        }
    };

    return new CleanableCase(new SoftReference<>(obj, null), c1, s1);
}
 
源代码8 项目: openjdk-jdk9   文件: CleanerTest.java
CleanableCase(Reference<Object> ref, Cleaner.Cleanable cleanup,
              Semaphore semaphore) {
    this.ref = ref;
    this.cleanup = cleanup;
    this.semaphore = semaphore;
    this.throwsEx = false;
    this.events = new int[4];
    this.eventNdx = 0;
}
 
源代码9 项目: openjdk-jdk9   文件: CleanerTest.java
CleanableCase(Reference<Object> ref, Cleaner.Cleanable cleanup,
              Semaphore semaphore,
              boolean throwsEx) {
    this.ref = ref;
    this.cleanup = cleanup;
    this.semaphore = semaphore;
    this.throwsEx = throwsEx;
    this.events = new int[4];
    this.eventNdx = 0;
}
 
源代码10 项目: openjdk-jdk9   文件: CleanerTest.java
public Cleaner.Cleanable getCleanable() {
    return cleanup;
}
 
 方法所在类
 同类方法