Created
September 23, 2015 08:47
-
-
Save premrajm/cfd8f348fca7fa85ce32 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | |
}); | |
} | |
} |
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
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?