0

我正在使用 MapDB 创建并行地图 - 想知道它是否安全以及是否可以以更好的方式完成。还假设每个销售表查询可以产生数百万条记录。

public static void main(String[] args){
        DB db = DBMaker.newFileDB("mapdbFile").transactionDisable().mmapFileEnablePartial().make();
        getEmployees().parallelStream().forEach(e -> createRecords(e, db));
    }

private static List<Employee> getEmployees(){
    /* return employees list */
}

private static void createRecords(Employee employee, DB db) {
    JdbcTemplate template = /* spring JdbcTemplate creation */
    String query = "select name from sales where emp_id = "+employee.getId();        
    final BTreeMap<String, Long> map = db.createTreeMap("Employee" + employee.getId())
            .nodeSize(32).comparator(String.CASE_INSENSITIVE_ORDER).make();
    template.query(query, rs -> {
        put(map, rs.getString("product_name"), rs.getLong("sales"));
    });
}
4

1 回答 1

0

DB 对象是同步的并且是线程安全的。所以是的,并行地图创建是安全的。

于 2015-07-29T07:26:53.007 回答