Skip to content

Commit 3f124c6

Browse files
author
Niall Pemberton
committed
IO-161 try to fix OutOfMemoryError being thrown by FileCleaningTrackerTestCase in Gump and fix a potential *hanging* situation.
Remove the tracker from the list first. Theres a potential loop-for-ever situation if for some reason the delete fails because the Tracker will have been removed from the queue but still be in the List - and this method loops until the List is empty. Hopefully this will also resolve the FileCleaningTrackerTestCase's OutOfMemoryError in Gump and Continuum. Its failing during the file.delete() operation - the test code to fill-up-memory continues until the Tracker List is zero. git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1005515 13f79535-47bb-0310-9956-ffa450edef68
1 parent a972940 commit 3f124c6

2 files changed

Lines changed: 2 additions & 5 deletions

File tree

src/main/java/org/apache/commons/io/FileCleaningTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,9 @@ public void run() {
204204
try {
205205
// Wait for a tracker to remove.
206206
Tracker tracker = (Tracker) q.remove(); // cannot return null
207+
trackers.remove(tracker);
207208
tracker.delete();
208209
tracker.clear();
209-
trackers.remove(tracker);
210210
} catch (InterruptedException e) {
211211
continue;
212212
}

src/test/java/org/apache/commons/io/FileCleaningTrackerTestCase.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import java.io.File;
2020
import java.io.RandomAccessFile;
2121
import java.lang.ref.ReferenceQueue;
22-
import java.lang.ref.SoftReference;
2322
import java.util.ArrayList;
2423
import java.util.List;
2524

@@ -281,12 +280,11 @@ public void testFileCleanerExitWhenFinished2() throws Exception {
281280
//-----------------------------------------------------------------------
282281
private void waitUntilTrackCount() throws Exception {
283282
int count = 0;
284-
SoftReference<?> ref = new SoftReference<Object>(new Object());
285283
while(theInstance.getTrackCount() != 0 && count++ < 5) {
286284
List<String> list = new ArrayList<String>();
287285
try {
288286
long i = 0;
289-
while (ref.get() != null) {
287+
while (theInstance.getTrackCount() != 0) {
290288
list.add("A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String A Big String " + (i++));
291289
}
292290
} catch (Throwable ignored) {
@@ -295,7 +293,6 @@ private void waitUntilTrackCount() throws Exception {
295293
list = null;
296294
System.gc();
297295
Thread.sleep(1000);
298-
ref = new SoftReference<Object>(new Object());
299296
}
300297
if (theInstance.getTrackCount() != 0) {
301298
throw new IllegalStateException("Your JVM is not releasing SoftReference, try running the testcase with less memory (-Xmx)");

0 commit comments

Comments
 (0)