我有一个大地图,我想使用 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");
}