Skip to content

Instantly share code, notes, and snippets.

@premrajm
Created September 23, 2015 08:47
Show Gist options
  • Save premrajm/cfd8f348fca7fa85ce32 to your computer and use it in GitHub Desktop.
Save premrajm/cfd8f348fca7fa85ce32 to your computer and use it in GitHub Desktop.
public class MapDBCreator {
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"));
});
}
}
@premrajm
Copy link
Author

This code is causing performance issues because of thread contention at MapDb threads are blocked at sun.nio.ch.FileChannelImpl#readInternal i Is there any better way to handle this?

@premrajm
Copy link
Author

Should I just go ahead with single file per map?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment