java map 多线程遍历把key,value 插入缓存数据库

图片说明
这是一个map 里面大概有10万数据,在这里我想改成多线程遍历map插入缓存数据库。
不知道怎么写。求大神赐教。

因为想到map get操作是不加锁的。所以不知道怎么保证一个key,value 插入一次。

你看这样行不行

public class MapTest {

    public static void main(String[] args) {
        Map<String, String> map = new HashMap<String, String>();
        for(int i = 0; i < 400; i++){
            map.put(String.valueOf(i), null);
        }
        Runnable runnable = new MyRunnable(map.entrySet().iterator());
        Thread t1 = new Thread(runnable);
        t1.setName("Thread1");
        Thread t2 = new Thread(runnable);
        t2.setName("Thread2");
        Thread t3 = new Thread(runnable);
        t3.setName("Thread3");
        t1.start();
        t2.start();
        t3.start();
    }

}

class MyRunnable implements Runnable {
    private Iterator<Map.Entry<String, String>> set = null;
    private Object lock = new Object();

    public MyRunnable(Iterator<Map.Entry<String, String>> set) {
        this.set = set;
    }

    public void run() {
        synchronized (lock) {
        while (set.hasNext()) {
                lock.notifyAll();
                System.out.println(Thread.currentThread().getName() + "读取到Key "
                        + set.next().getKey());
                try {
//                  Thread.sleep(1000);
                    lock.wait();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        lock.notifyAll();
        }
    }
}