IOException, SecurityException, IllegalArgumentException,
NoSuchFieldException, IllegalAccessException,
FilePersistenceTooBigForSerializationException, HeapException {
initialize(pathName, dataManager, useCache);
final Runtime runtime = Runtime.getRuntime();
final MemInspector memInspectorForMemory = new MemInspector();
addTemplate();
long maxMemUse = 0;
long maxMemUse2 = 0;
pageSetSize = 0;
readCacheMapSize = 0;
writeCacheMapSize = 0;
freePageRootNodeSize = 0;
usedPageRootNodeSize = 0;
final IDataAccessSession session = filePersistence
.createDataAccessSession();
initMemInspector();
session.open();
initializeByItemDuration();
boolean objectAddedInMemory = false;
long duration = 0;
final PrintWriter insertLogWriter = new PrintWriter(insertLogFilePath);
final InputStream inputStream = getClass().getResourceAsStream(
"/all.txt");
final BufferedReader reader = new BufferedReader(new InputStreamReader(
inputStream));
final long insertStartTime = System.currentTimeMillis();
int count;
for (count = 0; (System.currentTimeMillis() - insertStartTime) < 5 * 60 * 1000
&& !objectAddedInMemory && count < numberOfItem + 1; count++) {
// final ItemTemplateList itemTemplateList =
// getItemTemplateList(session);
// final ItemTemplate itemTemplate;
// switch (identifier % 3) {
// case 0:
// itemTemplate = itemTemplateList.getItemTemplate(1);
// break;
// case 1:
// itemTemplate = itemTemplateList.getItemTemplate(2);
// break;
// case 2:
// itemTemplate = itemTemplateList.getItemTemplate(3);
// break;
// default:
// itemTemplate = null;
// }
final int identifier = Integer.parseInt(reader.readLine());
addItem(session, identifier);
// consistencyCheck();
insertLogWriter.println(identifier);
if (count % BATCH_SIZE == BATCH_SIZE - 1) {
final long startTime = System.currentTimeMillis();
session.closeAndWait(EnumFilePersistenceCloseAction.SAVE);
final long currentTime = System.currentTimeMillis();
System.gc();
objectAddedInMemory = checkObjectAddedInMemory(byItemIndex);
duration += (currentTime - startTime);
final long byItem = duration * 1000 / (count + 1);
final long memUse = runtime.totalMemory()
- runtime.freeMemory();
byItemMem[byItemIndex] = (int) (memUse / 1024);
if (memUse > maxMemUse) {
maxMemUse = memUse;
}
byItemDuration[byItemIndex] = (int) byItem;
final StringBuilder builder = new StringBuilder();
builder.append('\n');
builder.append(duration);
builder.append(" mS ");
builder.append(count + 1);
builder.append(" appened, by item ");
builder.append(byItem);
builder.append(" µS\nmem used=");
builder.append(mem(memUse));
builder.append("\nmax= ");
builder.append(mem(maxMemUse));
if (OBJ_MEM_SIZE) {
final long memUse2 = memInspectorForMemory
.memoryUsed(filePersistence);
if (memUse2 > maxMemUse2) {// NOPMD
maxMemUse2 = memUse2;
}
byItemMem2[byItemIndex] = (int) (memUse2 / 1024);