0
我使用MapDB創建並行地圖 - 想知道它是否安全,可以以更好的方式完成。還假設每個銷售表查詢都可能導致百萬條記錄。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"));
});
}
它會比以串行方式創建地圖更快嗎? – Premraj