FilePersistenceTooBigForSerializationException {
/* create file persistence manager */
final IFilePersistence filePersistence =
/**/createFilePersistence(true/* remove files */);
/* create a data access session */
final IDataAccessSession session = filePersistence
.createDataAccessSession();
/* get operation start time */
final long startTime = System.currentTimeMillis();
/* create reference list of object currently in memory */
memInspector.inspect(this, false/* mark new */);
/* starting open session */
session.open();
/*
* create the map in memory and add it to persisted object
*/
Map<Integer, String> map = new PTreeMap<Integer, String>();
session.setObject("map", map);
int packet = 0;
/*
* add one million of entry in the persisted map
*/
for (int index = 0; index < 1000000; index++) {
/* get the persisted map */
map = getMap(session);
/* add an entry */
map.put(index, String.valueOf(index));
/*
* for each 10000 append: close the session saving data, then reopen
* session
*/
if (index / 10000 > packet) {
/*
* after 1000 add, save in file. Object in memory will be
* detached
*/
final int numberOfObjectStateBeforeSave = filePersistence
.getNumberOfObjectState();
/*
* saving close of data access session
*/
session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
/*
* log information about persistent objects
*/
final int modified = filePersistence.getNumberOfModified();
final int visited = filePersistence.getNumberOfVisited();
/*
* to show that for appends all the map is not loaded in memory
*/
System.out.println(// NOPMD
(index + 1) + " appened, "
+ (System.currentTimeMillis() - startTime)
+ " mS elapsed, "
+ numberOfObjectStateBeforeSave
+ " object loaded\n" + visited + " visited, "
+ modified + " modified, ");
/* unreference the map => will be garbaged by VM */
map = null;// NOPMD
/* re open for next append */
session.open();
packet++;
}
}
/* ending saving close */
session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
/*
* check if no memory leak, must not have object added in memory
*/
memInspector.inspect(this, true/* mar added */);