From 743a7edceb14915c43990a08e3b157295529236a Mon Sep 17 00:00:00 2001 From: David McKnight Date: Mon, 6 Dec 2010 17:11:58 +0000 Subject: [PATCH] [331922] [dstore] enable DataElement recycling --- .../eclipse/dstore/core/model/DataStore.java | 35 ++++++++++--------- .../core/util/DataElementRemover.java | 4 ++- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataStore.java b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataStore.java index 07c62af5be3..6d8c0892092 100644 --- a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataStore.java +++ b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/core/model/DataStore.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2009 IBM Corporation and others. + * Copyright (c) 2002, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -33,6 +33,7 @@ * David McKnight (IBM) - [287457] [dstore] problems with disconnect when readonly trace file * David McKnight (IBM) - [289891] [dstore] StringIndexOutOfBoundsException in getUserPreferencesDirectory when DSTORE_LOG_DIRECTORY is "" * David McKnight (IBM) - [294933] [dstore] RSE goes into loop + * David McKnight (IBM) - [331922] [dstore] enable DataElement recycling *******************************************************************************/ package org.eclipse.dstore.core.model; @@ -145,6 +146,7 @@ public final class DataStore private Random _random; private int _initialSize; + private int _MAX_FREE = 10000; private File _traceFileHandle; private RandomAccessFile _traceFile; @@ -190,7 +192,7 @@ public final class DataStore _isConnected = false; _logTimes = false; setSpiritModeOnState(); - _initialSize = _spiritModeOn && !isVirtual() ? SPIRIT_ON_INITIAL_SIZE : 100000; + _initialSize = _spiritModeOn && !isVirtual() ? SPIRIT_ON_INITIAL_SIZE : 10000; initialize(); } @@ -2706,7 +2708,10 @@ public final class DataStore public void addToRecycled(DataElement toRecycle) { - if (!_recycled.contains(toRecycle)) _recycled.add(0, toRecycle); + synchronized (_recycled){ + if (!_recycled.contains(toRecycle)) + _recycled.add(0, toRecycle); + } } /** @@ -3870,9 +3875,11 @@ public final class DataStore */ private void initElements(int size) { - for (int i = 0; i < size; i++) - { - _recycled.add(new DataElement(this)); + synchronized (_recycled){ + for (int i = 0; i < size; i++) + { + _recycled.add(new DataElement(this)); + } } } @@ -3891,20 +3898,15 @@ public final class DataStore if (numRecycled > 1) { synchronized (_recycled) - { - - /* + { if (numRecycled > _MAX_FREE) { int numRemoved = numRecycled - _MAX_FREE; for (int i = 1; i <= numRemoved; i++) - { - DataElement toRemove = (DataElement)_recycled.remove(numRemoved - i); - toRemove = null; - } - } - */ - + { + _recycled.remove(numRemoved - i); + } + } newObject = (DataElement) _recycled.remove((_recycled.size() - 1)); } } @@ -3974,6 +3976,7 @@ public final class DataStore synchronized (_hashMap) { _hashMap.remove(id); + addToRecycled(toDelete); } if (!isConnected() && from != null) diff --git a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/internal/core/util/DataElementRemover.java b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/internal/core/util/DataElementRemover.java index 620fccc0d0b..f4a7be10c8d 100644 --- a/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/internal/core/util/DataElementRemover.java +++ b/rse/plugins/org.eclipse.dstore.core/src/org/eclipse/dstore/internal/core/util/DataElementRemover.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2002, 2009 IBM Corporation and others. + * Copyright (c) 2002, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -16,6 +16,7 @@ * David McKnight (IBM) - [255390] check memory to determine whether to queue * David McKnight (IBM) - [261644] [dstore] remote search improvements * David McKnight (IBM) - [294933] [dstore] RSE goes into loop + * David McKnight (IBM) - [331922] [dstore] enable DataElement recycling *******************************************************************************/ package org.eclipse.dstore.internal.core.util; @@ -198,6 +199,7 @@ public class DataElementRemover extends Handler HashMap map = _dataStore.getHashMap(); synchronized (map){ map.remove(element.getId()); + _dataStore.addToRecycled(element); } }