< prev index next >

src/java.base/share/classes/sun/misc/Cleaner.java

Print this page




 125      *         cleanup code is run directly from the reference-handler thread,
 126      *         so it should be as simple and straightforward as possible.
 127      *
 128      * @return  The new cleaner
 129      */
 130     public static Cleaner create(Object ob, Runnable thunk) {
 131         if (thunk == null)
 132             return null;
 133         return add(new Cleaner(ob, thunk));
 134     }
 135 
 136     /**
 137      * Runs this cleaner, if it has not been run before.
 138      */
 139     public void clean() {
 140         if (!remove(this))
 141             return;
 142         try {
 143             thunk.run();
 144         } catch (final Throwable x) {
 145             AccessController.doPrivileged(new PrivilegedAction<Void>() {
 146                     public Void run() {
 147                         if (System.err != null)
 148                             new Error("Cleaner terminated abnormally", x)
 149                                 .printStackTrace();
 150                         System.exit(1);
 151                         return null;
 152                     }});
 153         }
 154     }
 155 
 156 }


 125      *         cleanup code is run directly from the reference-handler thread,
 126      *         so it should be as simple and straightforward as possible.
 127      *
 128      * @return  The new cleaner
 129      */
 130     public static Cleaner create(Object ob, Runnable thunk) {
 131         if (thunk == null)
 132             return null;
 133         return add(new Cleaner(ob, thunk));
 134     }
 135 
 136     /**
 137      * Runs this cleaner, if it has not been run before.
 138      */
 139     public void clean() {
 140         if (!remove(this))
 141             return;
 142         try {
 143             thunk.run();
 144         } catch (final Throwable x) {
 145             AccessController.doPrivileged(new PrivilegedAction<>() {
 146                     public Void run() {
 147                         if (System.err != null)
 148                             new Error("Cleaner terminated abnormally", x)
 149                                 .printStackTrace();
 150                         System.exit(1);
 151                         return null;
 152                     }});
 153         }
 154     }
 155 
 156 }
< prev index next >