Fix synchronisation.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sun, 20 Oct 2013 00:32:09 +0000 (02:32 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 28 Feb 2014 21:25:32 +0000 (22:25 +0100)
src/main/java/net/pterodactylus/sone/database/memory/MemoryDatabase.java

index 8c5c64f..8817016 100644 (file)
@@ -218,7 +218,12 @@ public class MemoryDatabase extends AbstractService implements Database {
                        @Override
                        public Sone build(Optional<SoneCreated> soneCreated) throws IllegalStateException {
                                Sone sone = super.build(soneCreated);
-                               sones.put(sone.getId(), sone);
+                               lock.writeLock().lock();
+                               try {
+                                       sones.put(sone.getId(), sone);
+                               } finally {
+                                       lock.writeLock().unlock();
+                               }
                                return sone;
                        }
                };