All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.hajdbc.util.BatchMap Maven / Gradle / Ivy

There is a newer version: 3.6.61
Show newest version
package net.sf.hajdbc.util;


import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

/**
 * HashMap batch support.
 * @author dib
 * @param 
 * @param 
 */
public class BatchMap {
  final transient ReentrantLock lock = new ReentrantLock();
  private final Map data = new HashMap<>();

  public void commit(Map map){
    lock.lock();
    try {
      data.clear();
      data.putAll(map);
    }finally {
      lock.unlock();
    }
  }

  public Map getData(){
    Map map = new HashMap<>();
    lock.lock();
    try {
      map.putAll(data);
    }finally {
      lock.unlock();
    }
    return map;
  }


}





© 2015 - 2024 Weber Informatics LLC | Privacy Policy