package org.ethereum.datasource;

import org.ethereum.db.ByteArrayWrapper;
import org.iq80.leveldb.DBException;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import static org.ethereum.util.ByteUtil.wrap;

public class HashMapDB implements KeyValueDataSource {

    Map<ByteArrayWrapper, byte[]> storage = new HashMap<>();


    @Override
    public void delete(byte[] arg0) throws DBException {
        storage.remove(wrap(arg0));
    }


    @Override
    public byte[] get(byte[] arg0) throws DBException {
        return storage.get(wrap(arg0));
    }


    @Override
    public byte[] put(byte[] key, byte[] value) throws DBException {
        return storage.put(wrap(key), value);
    }

    /**
     * Returns the number of items added to this Mock DB
     *
     * @return int
     */
    public int getAddedItems() {
        return storage.size();
    }

    @Override
    public void init() {

    }

    @Override
    public boolean isAlive() {
        return true;
    }

    @Override
    public void setName(String name) {

    }

    @Override
    public String getName() {
        return "in-memory";
    }

    @Override
    public Set<byte[]> keys() {
        Set<byte[]> keys = new HashSet<>();
        for (ByteArrayWrapper key : storage.keySet()){
            keys.add(key.getData());
        }
        return keys;
    }

    @Override
    public void updateBatch(Map<byte[], byte[]> rows) {
        for (byte[] key :  rows.keySet()){
            storage.put(wrap(key), rows.get(key));
        }
    }

    @Override
    public void close() {
        this.storage.clear();
    }
}
@@ -127,85 +127,9 @@
 til.
-HashMap;%0Aimport java.util.HashSet;%0Aimport java.util.Map;%0Aimport java.util.Set
+*
 ;%0A%0Ai
@@ -315,24 +315,37 @@
 %0A    public 
+synchronized 
 void delete(
@@ -443,24 +443,37 @@
 %0A    public 
+synchronized 
 byte%5B%5D get(b
@@ -578,16 +578,29 @@
  public 
+synchronized 
 byte%5B%5D p
@@ -812,16 +812,29 @@
  public 
+synchronized 
 int getA
@@ -1170,16 +1170,29 @@
  public 
+synchronized 
 Set%3Cbyte
@@ -1399,24 +1399,37 @@
 %0A    public 
+synchronized 
 void updateB
@@ -1593,24 +1593,37 @@
 %0A    public 
+synchronized 
 void close()

Make HashMapDB thread safe