Java Code Examples for java.lang.ref.Cleaner#Cleanable
The following examples show how to use
java.lang.ref.Cleaner#Cleanable .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example 2
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example 3
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * 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); }
Example 4
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 5
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 6
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 7
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
/** * 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); }
Example 8
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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; }
Example 9
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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; }
Example 10
Source File: CleanerTest.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
public Cleaner.Cleanable getCleanable() { return cleanup; }