Skip to content

Commit 0e3cb19

Browse files
committed
Memory improvement : uses Queue when reading a collection from WS to
allow items cleaning during the step
1 parent d67baff commit 0e3cb19

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

src/main/java/com/github/jrrdev/mantisbtsync/core/common/readers/AxisAuthItemsArrayReader.java

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
*/
2424
package com.github.jrrdev.mantisbtsync.core.common.readers;
2525

26+
import java.util.Arrays;
27+
import java.util.LinkedList;
28+
import java.util.Queue;
29+
2630
import org.apache.axis.client.Stub;
2731
import org.apache.axis.transport.http.HTTPConstants;
2832
import org.springframework.batch.item.ItemReader;
@@ -52,14 +56,14 @@ public class AxisAuthItemsArrayReader<T> extends
5256
private Stub clientStub;
5357

5458
/**
55-
* Index of the last read item.
59+
* Results array got from the WS.
5660
*/
57-
private int i = -1;
61+
private final Queue<T> items = new LinkedList<T>();
5862

5963
/**
60-
* Results array got from the WS.
64+
* Boolean indicating if the WS call have already been made or not.
6165
*/
62-
private T[] items;
66+
private boolean isCallPerformed = false;
6367

6468

6569
/**
@@ -104,17 +108,12 @@ public T read() throws Exception {
104108
authManager.getAuthCookie());
105109
}
106110

107-
if (i < 0) {
108-
items = invokeDelegateMethod();
109-
i = -1;
111+
if (!isCallPerformed) {
112+
final T[] itemsArray = invokeDelegateMethod();
113+
isCallPerformed = true;
114+
items.addAll(Arrays.asList(itemsArray));
110115
}
111116

112-
i++;
113-
if (items != null && i < items.length) {
114-
return items[i];
115-
} else {
116-
items = null;
117-
return null;
118-
}
117+
return items.poll();
119118
}
120119
}

0 commit comments

Comments
 (0)