69 public V get(long x, TimeUnit y)
70 throws InterruptedException,ExecutionException,TimeoutException
71 { return task.get(x, y); }
72 public boolean isDone() { return task.isDone(); }
73 public boolean isCancelled() { return task.isCancelled(); }
74 public boolean cancel(boolean x) { return task.cancel(x); }
75 public long getDelay(TimeUnit x) { return task.getDelay(x); }
76 public int compareTo(Delayed x) { return task.compareTo(x); }
77 };
78 }
79 }
80
81 void removeAll(ReferenceQueue<?> q, int n) throws InterruptedException {
82 for (int j = n; j--> 0; ) {
83 if (q.poll() == null) {
84 for (;;) {
85 System.gc();
86 if (q.remove(1000) != null)
87 break;
88 System.out.printf(
89 "%d/%d unqueued references remaining%n", j, n);
90 }
91 }
92 }
93 check(q.poll() == null);
94 }
95
96 void test(String[] args) throws Throwable {
97 final CustomPool pool = new CustomPool(10);
98 final int size = 100;
99 final ReferenceQueue<Object> q = new ReferenceQueue<>();
100 final List<WeakReference<?>> refs = new ArrayList<>(size);
101 final List<Future<?>> futures = new ArrayList<>(size);
102
103 // Schedule custom tasks with strong references.
104 class Task implements Runnable {
105 final Object x;
106 Task() { refs.add(new WeakReference<>(x = new Object(), q)); }
107 public void run() { System.out.println(x); }
108 }
109 // Give tasks added later earlier expiration, to ensure
|
69 public V get(long x, TimeUnit y)
70 throws InterruptedException,ExecutionException,TimeoutException
71 { return task.get(x, y); }
72 public boolean isDone() { return task.isDone(); }
73 public boolean isCancelled() { return task.isCancelled(); }
74 public boolean cancel(boolean x) { return task.cancel(x); }
75 public long getDelay(TimeUnit x) { return task.getDelay(x); }
76 public int compareTo(Delayed x) { return task.compareTo(x); }
77 };
78 }
79 }
80
81 void removeAll(ReferenceQueue<?> q, int n) throws InterruptedException {
82 for (int j = n; j--> 0; ) {
83 if (q.poll() == null) {
84 for (;;) {
85 System.gc();
86 if (q.remove(1000) != null)
87 break;
88 System.out.printf(
89 "%d/%d unqueued references remaining%n", j + 1, n);
90 }
91 }
92 }
93 check(q.poll() == null);
94 }
95
96 void test(String[] args) throws Throwable {
97 final CustomPool pool = new CustomPool(10);
98 final int size = 100;
99 final ReferenceQueue<Object> q = new ReferenceQueue<>();
100 final List<WeakReference<?>> refs = new ArrayList<>(size);
101 final List<Future<?>> futures = new ArrayList<>(size);
102
103 // Schedule custom tasks with strong references.
104 class Task implements Runnable {
105 final Object x;
106 Task() { refs.add(new WeakReference<>(x = new Object(), q)); }
107 public void run() { System.out.println(x); }
108 }
109 // Give tasks added later earlier expiration, to ensure
|