diff --git a/src/main/java/li/strolch/agent/impl/CachedAuditTrail.java b/src/main/java/li/strolch/agent/impl/CachedAuditTrail.java index 8449480a7..2469d1960 100644 --- a/src/main/java/li/strolch/agent/impl/CachedAuditTrail.java +++ b/src/main/java/li/strolch/agent/impl/CachedAuditTrail.java @@ -56,7 +56,8 @@ public class CachedAuditTrail implements AuditTrail { } @Override - public boolean hasAudit(StrolchTransaction tx, String type, Long id) { + public synchronized boolean hasAudit(StrolchTransaction tx, String type, Long id) { + return this.auditMap.containsElement(type, id); } @@ -73,7 +74,7 @@ public class CachedAuditTrail implements AuditTrail { } @Override - public long querySize(StrolchTransaction tx, String type, DateRange dateRange) { + public synchronized long querySize(StrolchTransaction tx, String type, DateRange dateRange) { long size = 0; Map byType = this.auditMap.getMap(type); @@ -89,17 +90,17 @@ public class CachedAuditTrail implements AuditTrail { } @Override - public Set getTypes(StrolchTransaction tx) { + public synchronized Set getTypes(StrolchTransaction tx) { return new HashSet<>(this.auditMap.keySet()); } @Override - public Audit getBy(StrolchTransaction tx, String type, Long id) { + public synchronized Audit getBy(StrolchTransaction tx, String type, Long id) { return this.auditMap.getElement(type, id); } @Override - public List getAllElements(StrolchTransaction tx, String type, DateRange dateRange) { + public synchronized List getAllElements(StrolchTransaction tx, String type, DateRange dateRange) { List elements = new ArrayList<>(); Map byType = this.auditMap.getMap(type); @@ -115,14 +116,14 @@ public class CachedAuditTrail implements AuditTrail { } @Override - public void add(StrolchTransaction tx, Audit audit) { + public synchronized void add(StrolchTransaction tx, Audit audit) { this.auditMap.addElement(audit.getElementType(), audit.getId(), audit); // last is to perform DB changes getDao(tx).save(audit); } @Override - public void addAll(StrolchTransaction tx, List audits) { + public synchronized void addAll(StrolchTransaction tx, List audits) { for (Audit audit : audits) { this.auditMap.addElement(audit.getElementType(), audit.getId(), audit); } @@ -131,7 +132,7 @@ public class CachedAuditTrail implements AuditTrail { } @Override - public Audit update(StrolchTransaction tx, Audit audit) { + public synchronized Audit update(StrolchTransaction tx, Audit audit) { Audit replacedAudit = this.auditMap.addElement(audit.getElementType(), audit.getId(), audit); // last is to perform DB changes getDao(tx).update(audit); @@ -139,7 +140,7 @@ public class CachedAuditTrail implements AuditTrail { } @Override - public List updateAll(StrolchTransaction tx, List audits) { + public synchronized List updateAll(StrolchTransaction tx, List audits) { List replacedAudits = new ArrayList<>(); for (Audit audit : audits) { Audit replacedAudit = this.auditMap.addElement(audit.getElementType(), audit.getId(), audit); @@ -152,14 +153,14 @@ public class CachedAuditTrail implements AuditTrail { } @Override - public void remove(StrolchTransaction tx, Audit audit) { + public synchronized void remove(StrolchTransaction tx, Audit audit) { this.auditMap.removeElement(audit.getElementType(), audit.getId()); // last is to perform DB changes getDao(tx).remove(audit); } @Override - public void removeAll(StrolchTransaction tx, List audits) { + public synchronized void removeAll(StrolchTransaction tx, List audits) { for (Audit audit : audits) { this.auditMap.removeElement(audit.getElementType(), audit.getId()); } @@ -169,7 +170,7 @@ public class CachedAuditTrail implements AuditTrail { } @Override - public long removeAll(StrolchTransaction tx, String type, DateRange dateRange) { + public synchronized long removeAll(StrolchTransaction tx, String type, DateRange dateRange) { Map byType = this.auditMap.getMap(type); if (byType == null) diff --git a/src/main/java/li/strolch/agent/impl/CachedElementMap.java b/src/main/java/li/strolch/agent/impl/CachedElementMap.java index 88f37f4cd..fc7a262bc 100644 --- a/src/main/java/li/strolch/agent/impl/CachedElementMap.java +++ b/src/main/java/li/strolch/agent/impl/CachedElementMap.java @@ -46,19 +46,19 @@ public abstract class CachedElementMap implements private Map> elementMap; public CachedElementMap() { - this.allKeys = Collections.synchronizedSet(new HashSet()); - this.elementMap = Collections.synchronizedMap(new HashMap>()); + this.allKeys = new HashSet(); + this.elementMap = new HashMap>(); } protected abstract StrolchDao getDao(StrolchTransaction tx); @Override - public boolean hasType(StrolchTransaction tx, String type) { + public synchronized boolean hasType(StrolchTransaction tx, String type) { return this.elementMap.containsKey(type); } @Override - public boolean hasElement(StrolchTransaction tx, String type, String id) { + public synchronized boolean hasElement(StrolchTransaction tx, String type, String id) { Map byType = this.elementMap.get(type); if (byType == null) return false; @@ -67,7 +67,7 @@ public abstract class CachedElementMap implements } @Override - public long querySize(StrolchTransaction tx) { + public synchronized long querySize(StrolchTransaction tx) { long size = 0L; for (String type : this.elementMap.keySet()) { @@ -79,7 +79,7 @@ public abstract class CachedElementMap implements } @Override - public long querySize(StrolchTransaction tx, String type) { + public synchronized long querySize(StrolchTransaction tx, String type) { Map byType = this.elementMap.get(type); if (byType == null) return 0L; @@ -87,12 +87,12 @@ public abstract class CachedElementMap implements } @Override - public T getTemplate(StrolchTransaction tx, String type) { + public synchronized T getTemplate(StrolchTransaction tx, String type) { return getBy(tx, StrolchConstants.TEMPLATE, type); } @Override - public T getBy(StrolchTransaction tx, String type, String id) { + public synchronized T getBy(StrolchTransaction tx, String type, String id) { Map byType = this.elementMap.get(type); if (byType == null) return null; @@ -101,7 +101,7 @@ public abstract class CachedElementMap implements } @Override - public List getAllElements(StrolchTransaction tx) { + public synchronized List getAllElements(StrolchTransaction tx) { List allElements = new ArrayList<>(); for (String type : this.elementMap.keySet()) { Map byType = this.elementMap.get(type); @@ -112,7 +112,7 @@ public abstract class CachedElementMap implements } @Override - public List getElementsBy(StrolchTransaction tx, String type) { + public synchronized List getElementsBy(StrolchTransaction tx, String type) { Map byType = this.elementMap.get(type); if (byType == null) return Collections.emptyList(); @@ -120,12 +120,12 @@ public abstract class CachedElementMap implements } @Override - public Set getTypes(StrolchTransaction tx) { + public synchronized Set getTypes(StrolchTransaction tx) { return new HashSet<>(this.elementMap.keySet()); } @Override - public Set getAllKeys(StrolchTransaction tx) { + public synchronized Set getAllKeys(StrolchTransaction tx) { Set keys = new HashSet<>(); for (String type : this.elementMap.keySet()) { Map byType = this.elementMap.get(type); @@ -135,7 +135,7 @@ public abstract class CachedElementMap implements } @Override - public Set getKeysBy(StrolchTransaction tx, String type) { + public synchronized Set getKeysBy(StrolchTransaction tx, String type) { Map byType = this.elementMap.get(type); if (byType == null) return Collections.emptySet(); @@ -143,7 +143,7 @@ public abstract class CachedElementMap implements } @Override - public void add(StrolchTransaction tx, T element) { + public synchronized void add(StrolchTransaction tx, T element) { DBC.PRE.assertNotNull("Transaction may not be null!", tx); //$NON-NLS-1$ DBC.PRE.assertNotNull("Element may not be null!", element); //$NON-NLS-1$ @@ -151,7 +151,7 @@ public abstract class CachedElementMap implements } @Override - public T update(StrolchTransaction tx, T element) { + public synchronized T update(StrolchTransaction tx, T element) { DBC.PRE.assertNotNull("Transaction may not be null!", tx); //$NON-NLS-1$ DBC.PRE.assertNotNull("Element may not be null!", element); //$NON-NLS-1$ @@ -162,48 +162,41 @@ public abstract class CachedElementMap implements throw new StrolchPersistenceException(msg); } - T replacedElement; - synchronized (byType) { - if (byType.remove(element.getId()) == null) { - msg = MessageFormat.format(msg, element.getLocator()); - throw new StrolchPersistenceException(msg); - } - replacedElement = byType.put(element.getId(), element); - getDao(tx).update(element); + if (byType.remove(element.getId()) == null) { + msg = MessageFormat.format(msg, element.getLocator()); + throw new StrolchPersistenceException(msg); } + T replacedElement = byType.put(element.getId(), element); + getDao(tx).update(element); return replacedElement; } @Override - public void remove(StrolchTransaction tx, T element) { + public synchronized void remove(StrolchTransaction tx, T element) { DBC.PRE.assertNotNull("Transaction may not be null!", tx); //$NON-NLS-1$ DBC.PRE.assertNotNull("Element may not be null!", element); //$NON-NLS-1$ String msg = "The element {0} can not be removed as it does not exist!"; //$NON-NLS-1$ - synchronized (this.elementMap) { - Map byType = this.elementMap.get(element.getType()); - if (byType == null) { - msg = MessageFormat.format(msg, element.getLocator()); - throw new StrolchPersistenceException(msg); - } + Map byType = this.elementMap.get(element.getType()); + if (byType == null) { + msg = MessageFormat.format(msg, element.getLocator()); + throw new StrolchPersistenceException(msg); + } - synchronized (byType) { - if (byType.remove(element.getId()) == null) { - msg = MessageFormat.format(msg, element.getLocator()); - throw new StrolchPersistenceException(msg); - } - if (byType.isEmpty()) { - synchronized (this.elementMap) { - if (byType.isEmpty()) - this.elementMap.remove(element.getType()); - } - } - this.allKeys.remove(element.getId()); - getDao(tx).remove(element); + if (byType.remove(element.getId()) == null) { + msg = MessageFormat.format(msg, element.getLocator()); + throw new StrolchPersistenceException(msg); + } + if (byType.isEmpty()) { + synchronized (this.elementMap) { + if (byType.isEmpty()) + this.elementMap.remove(element.getType()); } } + this.allKeys.remove(element.getId()); + getDao(tx).remove(element); } /** @@ -214,33 +207,28 @@ public abstract class CachedElementMap implements * @param element * @param tx */ - void insert(T element, StrolchTransaction tx) { + synchronized void insert(T element, StrolchTransaction tx) { if (this.allKeys.contains(element.getId())) { String msg = "An element already exists with the id " + element.getId() //$NON-NLS-1$ + ". Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$ throw new StrolchPersistenceException(msg); } - Map byType; - synchronized (this.elementMap) { - byType = this.elementMap.get(element.getType()); - if (byType == null) { - byType = Collections.synchronizedMap(new HashMap()); - this.elementMap.put(element.getType(), byType); - } + Map byType = this.elementMap.get(element.getType()); + if (byType == null) { + byType = Collections.synchronizedMap(new HashMap()); + this.elementMap.put(element.getType(), byType); } - synchronized (byType) { - if (byType.containsKey(element.getId())) { - String msg = MessageFormat.format("The element {0} already exists!", element.getLocator()); //$NON-NLS-1$ - throw new StrolchPersistenceException(msg); - } - - byType.put(element.getId(), element); - this.allKeys.add(element.getId()); - if (tx != null) - getDao(tx).save(element); + if (byType.containsKey(element.getId())) { + String msg = MessageFormat.format("The element {0} already exists!", element.getLocator()); //$NON-NLS-1$ + throw new StrolchPersistenceException(msg); } + + byType.put(element.getId(), element); + this.allKeys.add(element.getId()); + if (tx != null) + getDao(tx).save(element); } private Map> sortElementsToType(List elements) { @@ -257,7 +245,7 @@ public abstract class CachedElementMap implements } @Override - public void addAll(StrolchTransaction tx, List elements) { + public synchronized void addAll(StrolchTransaction tx, List elements) { DBC.PRE.assertNotNull("Transaction may not be null!", tx); //$NON-NLS-1$ DBC.PRE.assertNotNull("Elements may not be null!", elements); //$NON-NLS-1$ @@ -271,26 +259,22 @@ public abstract class CachedElementMap implements for (String type : map.keySet()) { Map byType; - synchronized (this.elementMap) { - byType = this.elementMap.get(type); - if (byType == null) { - byType = new HashMap<>(); - this.elementMap.put(type, byType); + byType = this.elementMap.get(type); + if (byType == null) { + byType = new HashMap<>(); + this.elementMap.put(type, byType); + } + + List newByType = map.get(type); + for (T element : newByType) { + if (byType.containsKey(element.getId())) { + String msg = "An element already exists with the id {0}. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$ + msg = MessageFormat.format(msg, element.getId()); + throw new StrolchPersistenceException(msg); } - List newByType = map.get(type); - for (T element : newByType) { - synchronized (byType) { - if (byType.containsKey(element.getId())) { - String msg = "An element already exists with the id {0}. Elements of the same class must always have a unique id, regardless of their type!"; //$NON-NLS-1$ - msg = MessageFormat.format(msg, element.getId()); - throw new StrolchPersistenceException(msg); - } - - byType.put(element.getId(), element); - this.allKeys.add(element.getId()); - } - } + byType.put(element.getId(), element); + this.allKeys.add(element.getId()); } } @@ -299,7 +283,7 @@ public abstract class CachedElementMap implements } @Override - public List updateAll(StrolchTransaction tx, List elements) { + public synchronized List updateAll(StrolchTransaction tx, List elements) { DBC.PRE.assertNotNull("Transaction may not be null!", tx); //$NON-NLS-1$ DBC.PRE.assertNotNull("Elements may not be null!", elements); //$NON-NLS-1$ @@ -317,24 +301,20 @@ public abstract class CachedElementMap implements for (String type : map.keySet()) { List list = map.get(type); - synchronized (this.elementMap) { - Map byType = this.elementMap.get(type); - if (byType == null) { - msg = MessageFormat.format(msg, list.get(0).getLocator()); + Map byType = this.elementMap.get(type); + if (byType == null) { + msg = MessageFormat.format(msg, list.get(0).getLocator()); + throw new StrolchPersistenceException(msg); + } + + for (T element : list) { + T replacedElement = byType.remove(element.getId()); + if (replacedElement == null) { + msg = MessageFormat.format(msg, element.getLocator()); throw new StrolchPersistenceException(msg); } - - synchronized (byType) { - for (T element : list) { - T replacedElement = byType.remove(element.getId()); - if (replacedElement == null) { - msg = MessageFormat.format(msg, element.getLocator()); - throw new StrolchPersistenceException(msg); - } - byType.put(element.getId(), element); - replacedElements.add(replacedElement); - } - } + byType.put(element.getId(), element); + replacedElements.add(replacedElement); } } @@ -345,7 +325,7 @@ public abstract class CachedElementMap implements } @Override - public void removeAll(StrolchTransaction tx, List elements) { + public synchronized void removeAll(StrolchTransaction tx, List elements) { DBC.PRE.assertNotNull("Transaction may not be null!", tx); //$NON-NLS-1$ DBC.PRE.assertNotNull("Elements may not be null!", elements); //$NON-NLS-1$ @@ -361,26 +341,22 @@ public abstract class CachedElementMap implements for (String type : map.keySet()) { List list = map.get(type); - synchronized (this.elementMap) { - Map byType = this.elementMap.get(type); - if (byType == null) { - msg = MessageFormat.format(msg, list.get(0).getLocator()); + Map byType = this.elementMap.get(type); + if (byType == null) { + msg = MessageFormat.format(msg, list.get(0).getLocator()); + throw new StrolchPersistenceException(msg); + } + for (T element : list) { + if (byType.remove(element.getId()) == null) { + msg = MessageFormat.format(msg, element.getLocator()); throw new StrolchPersistenceException(msg); } - synchronized (byType) { - for (T element : list) { - if (byType.remove(element.getId()) == null) { - msg = MessageFormat.format(msg, element.getLocator()); - throw new StrolchPersistenceException(msg); - } - this.allKeys.remove(element.getId()); + this.allKeys.remove(element.getId()); - if (byType.isEmpty()) { - synchronized (this.elementMap) { - if (byType.isEmpty()) - this.elementMap.remove(type); - } - } + if (byType.isEmpty()) { + synchronized (this.elementMap) { + if (byType.isEmpty()) + this.elementMap.remove(type); } } } @@ -391,21 +367,19 @@ public abstract class CachedElementMap implements } @Override - public long removeAll(StrolchTransaction tx) { + public synchronized long removeAll(StrolchTransaction tx) { if (this.elementMap.isEmpty()) return 0; long removed = 0; - synchronized (this.elementMap) { - Set types = this.elementMap.keySet(); - for (String type : types) { + Set types = this.elementMap.keySet(); + for (String type : types) { - Map byType = this.elementMap.get(type); - removed += byType.size(); - byType.clear(); - } + Map byType = this.elementMap.get(type); + removed += byType.size(); + byType.clear(); } // last is to perform DB changes @@ -420,22 +394,20 @@ public abstract class CachedElementMap implements } @Override - public long removeAllBy(StrolchTransaction tx, String type) { + public synchronized long removeAllBy(StrolchTransaction tx, String type) { long removed = 0; String msg = "The elements with type {0} can not be removed as they do not exist!"; //$NON-NLS-1$ - synchronized (this.elementMap) { - Map byType = this.elementMap.get(type); - if (byType == null) { - msg = MessageFormat.format(msg, type); - throw new StrolchPersistenceException(msg); - } - - removed = byType.size(); - byType.clear(); + Map byType = this.elementMap.get(type); + if (byType == null) { + msg = MessageFormat.format(msg, type); + throw new StrolchPersistenceException(msg); } + removed = byType.size(); + byType.clear(); + // last is to perform DB changes long daoRemoved = getDao(tx).removeAllBy(type); diff --git a/src/main/java/li/strolch/persistence/inmemory/InMemoryAuditDao.java b/src/main/java/li/strolch/persistence/inmemory/InMemoryAuditDao.java index a0ab17153..597f4c978 100644 --- a/src/main/java/li/strolch/persistence/inmemory/InMemoryAuditDao.java +++ b/src/main/java/li/strolch/persistence/inmemory/InMemoryAuditDao.java @@ -39,7 +39,7 @@ public class InMemoryAuditDao implements AuditDao { } @Override - public boolean hasElement(String type, Long id) { + public synchronized boolean hasElement(String type, Long id) { Map byType = this.auditMap.getMap(type); if (byType == null) return false; @@ -47,7 +47,7 @@ public class InMemoryAuditDao implements AuditDao { } @Override - public long querySize(DateRange dateRange) { + public synchronized long querySize(DateRange dateRange) { long size = 0L; for (String type : this.auditMap.keySet()) { @@ -62,7 +62,7 @@ public class InMemoryAuditDao implements AuditDao { } @Override - public long querySize(String type, DateRange dateRange) { + public synchronized long querySize(String type, DateRange dateRange) { long size = 0L; Map byType = this.auditMap.getMap(type); for (Audit audit : byType.values()) { @@ -73,17 +73,17 @@ public class InMemoryAuditDao implements AuditDao { } @Override - public Audit queryBy(String type, Long id) { + public synchronized Audit queryBy(String type, Long id) { return this.auditMap.getElement(type, id); } @Override - public Set queryTypes() { + public synchronized Set queryTypes() { return this.auditMap.keySet(); } @Override - public List queryAll(String type, DateRange dateRange) { + public synchronized List queryAll(String type, DateRange dateRange) { List audits = new ArrayList<>(); Map byType = this.auditMap.getMap(type); if (byType == null) @@ -97,43 +97,43 @@ public class InMemoryAuditDao implements AuditDao { } @Override - public void save(Audit audit) { + public synchronized void save(Audit audit) { this.auditMap.addElement(audit.getElementType(), audit.getId(), audit); } @Override - public void saveAll(List audits) { + public synchronized void saveAll(List audits) { for (Audit audit : audits) { this.auditMap.addElement(audit.getElementType(), audit.getId(), audit); } } @Override - public void update(Audit audit) { + public synchronized void update(Audit audit) { this.auditMap.addElement(audit.getElementType(), audit.getId(), audit); } @Override - public void updateAll(List audits) { + public synchronized void updateAll(List audits) { for (Audit audit : audits) { this.auditMap.addElement(audit.getElementType(), audit.getId(), audit); } } @Override - public void remove(Audit audit) { + public synchronized void remove(Audit audit) { this.auditMap.removeElement(audit.getElementType(), audit.getId()); } @Override - public void removeAll(List audits) { + public synchronized void removeAll(List audits) { for (Audit audit : audits) { this.auditMap.removeElement(audit.getElementType(), audit.getId()); } } @Override - public long removeAll(String type, DateRange dateRange) { + public synchronized long removeAll(String type, DateRange dateRange) { Map byType = this.auditMap.getMap(type); if (byType == null) diff --git a/src/main/java/li/strolch/persistence/inmemory/InMemoryDao.java b/src/main/java/li/strolch/persistence/inmemory/InMemoryDao.java index ae7277cbe..c18a827fa 100644 --- a/src/main/java/li/strolch/persistence/inmemory/InMemoryDao.java +++ b/src/main/java/li/strolch/persistence/inmemory/InMemoryDao.java @@ -21,7 +21,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public boolean hasElement(String type, String id) { + public synchronized boolean hasElement(String type, String id) { Map byType = this.elementMap.get(type); if (byType == null) return false; @@ -29,7 +29,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public long querySize() { + public synchronized long querySize() { long size = 0; for (String type : this.elementMap.keySet()) { Map byType = this.elementMap.get(type); @@ -39,7 +39,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public long querySize(String type) { + public synchronized long querySize(String type) { Map byType = this.elementMap.get(type); if (byType == null) return 0; @@ -47,7 +47,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public Set queryKeySet() { + public synchronized Set queryKeySet() { Set keySet = new HashSet<>(); for (String type : this.elementMap.keySet()) { @@ -61,7 +61,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public Set queryKeySet(String type) { + public synchronized Set queryKeySet(String type) { Map byType = this.elementMap.get(type); if (byType == null) return new HashSet<>(0); @@ -69,12 +69,12 @@ public class InMemoryDao implements StrolchDao { } @Override - public Set queryTypes() { + public synchronized Set queryTypes() { return new HashSet<>(this.elementMap.keySet()); } @Override - public T queryBy(String type, String id) { + public synchronized T queryBy(String type, String id) { Map byType = this.elementMap.get(type); if (byType == null) return null; @@ -82,7 +82,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public List queryAll() { + public synchronized List queryAll() { List elements = new ArrayList<>(); for (String type : this.elementMap.keySet()) { Map byType = this.elementMap.get(type); @@ -95,7 +95,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public List queryAll(String type) { + public synchronized List queryAll(String type) { Map byType = this.elementMap.get(type); if (byType == null) return new ArrayList<>(0); @@ -103,7 +103,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public void save(T element) { + public synchronized void save(T element) { Map byType = this.elementMap.get(element.getType()); if (byType == null) { byType = new HashMap<>(); @@ -120,14 +120,14 @@ public class InMemoryDao implements StrolchDao { } @Override - public void saveAll(List elements) { + public synchronized void saveAll(List elements) { for (T element : elements) { save(element); } } @Override - public void update(T element) { + public synchronized void update(T element) { Map byType = this.elementMap.get(element.getType()); if (byType == null) { byType = new HashMap<>(); @@ -138,14 +138,14 @@ public class InMemoryDao implements StrolchDao { } @Override - public void updateAll(List elements) { + public synchronized void updateAll(List elements) { for (T element : elements) { update(element); } } @Override - public void remove(T element) { + public synchronized void remove(T element) { Map byType = this.elementMap.get(element.getType()); if (byType != null) { byType.remove(element.getId()); @@ -157,14 +157,14 @@ public class InMemoryDao implements StrolchDao { } @Override - public void removeAll(List elements) { + public synchronized void removeAll(List elements) { for (T element : elements) { remove(element); } } @Override - public long removeAll() { + public synchronized long removeAll() { long removed = 0; Set keySet = new HashSet(this.elementMap.keySet()); @@ -178,7 +178,7 @@ public class InMemoryDao implements StrolchDao { } @Override - public long removeAllBy(String type) { + public synchronized long removeAllBy(String type) { Map byType = this.elementMap.remove(type); if (byType == null) return 0;