test/java/lang/ref/EarlyTimeout.java

Print this page




  65         }
  66         startedSignal.await();
  67         referent = null;
  68         System.gc();
  69         for (EarlyTimeout thread : threads) {
  70             thread.join();
  71         }
  72         if (weakReference.get() != null) {
  73             throw new RuntimeException("weakReference was not cleared");
  74         }
  75         int nonNullRefCount = 0;
  76         for (EarlyTimeout thread : threads) {
  77             if (thread.reference == null && thread.actual < TIMEOUT) {
  78                 throw new RuntimeException("elapsed time " + thread.actual
  79                         + " is less than timeout " + TIMEOUT);
  80             }
  81             if (thread.reference != null && thread.reference == weakReference) {
  82                 nonNullRefCount++;
  83             }
  84         }
  85         if (nonNullRefCount != 1) {
  86             throw new RuntimeException("more than one references were removed from queue");
  87         }
  88     }
  89 
  90     public void run() {
  91         try {
  92             startedSignal.countDown();
  93             long start = System.currentTimeMillis();
  94             reference = queue.remove(TIMEOUT);
  95             actual = System.currentTimeMillis() - start;
  96         } catch (InterruptedException ex) {
  97             throw new RuntimeException(ex);
  98         }
  99     }
 100 }


  65         }
  66         startedSignal.await();
  67         referent = null;
  68         System.gc();
  69         for (EarlyTimeout thread : threads) {
  70             thread.join();
  71         }
  72         if (weakReference.get() != null) {
  73             throw new RuntimeException("weakReference was not cleared");
  74         }
  75         int nonNullRefCount = 0;
  76         for (EarlyTimeout thread : threads) {
  77             if (thread.reference == null && thread.actual < TIMEOUT) {
  78                 throw new RuntimeException("elapsed time " + thread.actual
  79                         + " is less than timeout " + TIMEOUT);
  80             }
  81             if (thread.reference != null && thread.reference == weakReference) {
  82                 nonNullRefCount++;
  83             }
  84         }
  85         if (nonNullRefCount > 1) {
  86             throw new RuntimeException("more than one references were removed from queue");
  87         }
  88     }
  89 
  90     public void run() {
  91         try {
  92             startedSignal.countDown();
  93             long start = System.currentTimeMillis();
  94             reference = queue.remove(TIMEOUT);
  95             actual = System.currentTimeMillis() - start;
  96         } catch (InterruptedException ex) {
  97             throw new RuntimeException(ex);
  98         }
  99     }
 100 }