jdk/test/java/util/zip/ZipFile/FinalizeZipFile.java
changeset 22124 8a31f2817571
parent 15295 1d90347088c3
child 27031 2a1bbbaacbe8
equal deleted inserted replaced
22123:fac5d9194929 22124:8a31f2817571
     1 /*
     1 /*
     2  * Copyright (c) 2010, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    25  * @bug 7007609 7009618
    25  * @bug 7007609 7009618
    26  * @summary Check that ZipFile objects are always collected
    26  * @summary Check that ZipFile objects are always collected
    27  */
    27  */
    28 
    28 
    29 import java.io.*;
    29 import java.io.*;
    30 import java.nio.*;
       
    31 import java.util.Random;
    30 import java.util.Random;
    32 import java.util.zip.*;
    31 import java.util.zip.*;
    33 import java.util.concurrent.CountDownLatch;
    32 import java.util.concurrent.CountDownLatch;
    34 import java.util.concurrent.TimeUnit;
       
    35 
    33 
    36 public class FinalizeZipFile {
    34 public class FinalizeZipFile {
    37 
    35 
    38     private final static CountDownLatch finalizersDone = new CountDownLatch(3);
    36     private final static CountDownLatch finalizersDone = new CountDownLatch(3);
    39 
    37 
    41 
    39 
    42         public InstrumentedZipFile(File f) throws Exception {
    40         public InstrumentedZipFile(File f) throws Exception {
    43             super(f);
    41             super(f);
    44             System.out.printf("Using %s%n", f.getPath());
    42             System.out.printf("Using %s%n", f.getPath());
    45         }
    43         }
       
    44         @Override
    46         protected void finalize() throws IOException {
    45         protected void finalize() throws IOException {
    47             System.out.printf("Killing %s%n", getName());
    46             System.out.printf("Killing %s%n", getName());
    48             super.finalize();
    47             super.finalize();
    49             finalizersDone.countDown();
    48             finalizersDone.countDown();
    50         }
    49         }
    79 
    78 
    80     public static void realMain(String[] args) throws Throwable {
    79     public static void realMain(String[] args) throws Throwable {
    81         makeGarbage();
    80         makeGarbage();
    82 
    81 
    83         System.gc();
    82         System.gc();
    84         finalizersDone.await(5, TimeUnit.SECONDS);
    83         finalizersDone.await();
    85 
    84 
    86         // Not all ZipFiles were collected?
    85         // Not all ZipFiles were collected?
    87         equal(finalizersDone.getCount(), 0L);
    86         equal(finalizersDone.getCount(), 0L);
    88     }
    87     }
    89 
    88