jdk/src/share/classes/java/io/DeleteOnExitHook.java
changeset 7803 56bc97d69d93
parent 5506 202f599c92aa
child 9035 1255eb81cc2f
equal deleted inserted replaced
7802:74f2ee2b62ba 7803:56bc97d69d93
    32  * A set is used both to prevent double-insertion of the same file as well as offer
    32  * A set is used both to prevent double-insertion of the same file as well as offer
    33  * quick removal.
    33  * quick removal.
    34  */
    34  */
    35 
    35 
    36 class DeleteOnExitHook {
    36 class DeleteOnExitHook {
    37     private static LinkedHashSet<String> files = new LinkedHashSet<String>();
    37     private static LinkedHashSet<String> files = new LinkedHashSet<>();
    38     static {
    38     static {
    39         // DeleteOnExitHook must be the last shutdown hook to be invoked.
    39         // DeleteOnExitHook must be the last shutdown hook to be invoked.
    40         // Application shutdown hooks may add the first file to the
    40         // Application shutdown hooks may add the first file to the
    41         // delete on exit list and cause the DeleteOnExitHook to be
    41         // delete on exit list and cause the DeleteOnExitHook to be
    42         // registered during shutdown in progress. So set the
    42         // registered during shutdown in progress. So set the
    69         synchronized (DeleteOnExitHook.class) {
    69         synchronized (DeleteOnExitHook.class) {
    70             theFiles = files;
    70             theFiles = files;
    71             files = null;
    71             files = null;
    72         }
    72         }
    73 
    73 
    74         ArrayList<String> toBeDeleted = new ArrayList<String>(theFiles);
    74         ArrayList<String> toBeDeleted = new ArrayList<>(theFiles);
    75 
    75 
    76         // reverse the list to maintain previous jdk deletion order.
    76         // reverse the list to maintain previous jdk deletion order.
    77         // Last in first deleted.
    77         // Last in first deleted.
    78         Collections.reverse(toBeDeleted);
    78         Collections.reverse(toBeDeleted);
    79         for (String filename : toBeDeleted) {
    79         for (String filename : toBeDeleted) {