我想要使用JDBM2(JDBM2的第一次用户)持久保存大型地图。
我对JDBM2演示程序进行了一些简单的编辑。但是,当我提取存储的值时,我得到了ClassCast Exceptions。
这是代码。任何帮助将不胜感激。
[另外,是否可以这种方式使用JDBM2。这些示例不构建,关闭,重新打开,使用。他们建立,使用,关闭]
public static void main(String[] args) throws IOException {
/** open db */
RecordManager recman = RecordManagerFactory.createRecordManager("hugedata");
PrimaryTreeMap<String, double[][]> db = recman.treeMap("hugemap");
/** insert some records */
int aBigNumber = 1000;
int aSmallerNumber = 100;
for (long i = 0; i < aBigNumber; i++) {
db.put(Long.toString(i), new double[9][9]);
if (i % aSmallerNumber == 0) {
/** Commit periodically, otherwise program would run out of memory */
recman.commit();
System.out.println(i);
}
}
recman.commit();
recman.close();
//now that the database is built we need to load it from file...otherwise we are cheating
//open the database to use it...
recman = RecordManagerFactory.createRecordManager("hugedata");
PrimaryTreeMap<String, double[][]> revivedDB = recman.treeMap("hugemap");
//ClassCastException thrown here
double[][] aStoredValue = revivedDB.get(Long.toString(10));
recman.close();
System.out.println("DONE");
}