FilePersistenceNotSerializableException,
FilePersistenceClassNotFoundException,
FilePersistenceDataCorruptedException,
FilePersistenceTooBigForSerializationException {
final int max = 100000;
final IExclusiveDataAccessSession session = filePersistence
.createExclusiveDataAccessSession();
session.open();
// List<Integer> bigList = new PLinkedList<Integer>(); // bigList
// instance
// // is in memory
session.setObject("myBigList", new PLinkedList<Integer>());// NOPMD
session.save();
List<Integer> bigList = (List<Integer>) session.getObject("myBigList");
for (int count = 0; count < max; count++) {
final int value = aValue(count);
bigList.add(value); // this make bigList growing in memory
if (count % 100 == 1) {
session.save();
final int numberOfObjectState = filePersistence
.getNumberOfObjectState();
System.out.println(count + " " + numberOfObjectState);// NOPMD
}
}
session.save();
System.out.println("--- iterate ---");// NOPMD
session.setObject("myBigList", bigList);
bigList = null; // NOPMD no more reference the big list
session.save(); // after this the garbage collector can free memory of
// the big list
bigList = (List<Integer>) session.getObject("myBigList"); // witchery of
// lazy load
// : all the
// big list
// is not
// loaded in
// memory
int count = 0;
for (final int value : bigList) {
doSomething(value);
if (count % 100 == 1) {
session.save();
final int numberOfObjectState = filePersistence
.getNumberOfObjectState();
System.out.println(count + " " + numberOfObjectState);// NOPMD
}
count++;
}
session.close();
}