创建mapdb停止添加32个项目进入HashMap的
问题描述:
这里以后是我的对象的定义:创建mapdb停止添加32个项目进入HashMap的
public class Tuple_comparable implements Serializable, Comparable<Tuple_comparable> {
public String arg1_surface;
public String arg1_type;
public boolean arg1_type_equals;
public String relation;
public String arg2_surface;
public String arg2_type;
public boolean arg2_type_equals;
public Long count;
@Override
public boolean equals(Object o) {
if (!(o instanceof Tuple_comparable))
return false;
Tuple_comparable oo = (Tuple_comparable)o;
if(oo.arg1_type.length() != this.arg1_type.length())
return false;
if(oo.relation.length() != this.relation.length())
return false;
if(oo.arg2_type.length() != this.arg2_type.length())
return false;
if(!oo.arg1_type.equals(this.arg1_type))
return false;
if(!oo.arg2_type.equals(this.arg2_type))
return false;
if(!oo.relation.equals(this.relation))
return false;
return true;
}
@Override
public int hashCode() {
return this.arg1_type.length() + this.relation.length() + this.arg2_type.length();
}
@Override
public int compareTo(Tuple_comparable o) {
return 1;
}
}
这里是我如何使用的创建mapdb:
DB db = DBMaker.newFileDB(new File(folder + "unique_pairs_withDenoms_directed_forward_test_1" + "_mapdb.bin"))
//.closeOnJvmShutdown()
.make();
// Create a Map:
Map<Tuple_comparable,long[]> myMap = db.getTreeMap("testmap");
int i = 0;
for(i = 0; i < 100000; i++) {
// Work with the Map using the normal Map API.
Tuple_comparable tc = new Tuple_comparable();
tc.arg1_surface = ""+ i;
tc.arg1_type = "" + i;
tc.arg1_type_equals = true;
tc.relation = "" + i;
tc.arg2_surface = "";
tc.arg2_type = "";
tc.arg2_type_equals = false;
tc.count = (long) 2222222;
long[] count = {1,2,3,4,4};
i++;
myMap.put(tc, count);
}
db.commit();
db.close();
当我运行它,我看到了如下:
Proccessed = % 0.001
After myMap.size() = 0
Proccessed = % 0.003
After myMap.size() = 1
Proccessed = % 0.005
After myMap.size() = 2
Proccessed = % 0.007
After myMap.size() = 3
Proccessed = % 0.009
After myMap.size() = 4
Proccessed = % 0.011
After myMap.size() = 5
Proccessed = % 0.013
After myMap.size() = 6
Proccessed = % 0.015
After myMap.size() = 7
Proccessed = % 0.017
After myMap.size() = 8
Proccessed = % 0.019
After myMap.size() = 9
Proccessed = % 0.021
After myMap.size() = 10
Proccessed = % 0.023
After myMap.size() = 11
Proccessed = % 0.025
After myMap.size() = 12
Proccessed = % 0.027
After myMap.size() = 13
Proccessed = % 0.029
After myMap.size() = 14
Proccessed = % 0.031
After myMap.size() = 15
Proccessed = % 0.033
After myMap.size() = 16
Proccessed = % 0.035
After myMap.size() = 17
Proccessed = % 0.037
After myMap.size() = 18
Proccessed = % 0.039
After myMap.size() = 19
Proccessed = % 0.041
After myMap.size() = 20
Proccessed = % 0.043
After myMap.size() = 21
Proccessed = % 0.045
After myMap.size() = 22
Proccessed = % 0.047
After myMap.size() = 23
Proccessed = % 0.049
After myMap.size() = 24
Proccessed = % 0.051
After myMap.size() = 25
Proccessed = % 0.053
After myMap.size() = 26
Proccessed = % 0.055
After myMap.size() = 27
Proccessed = % 0.057
After myMap.size() = 28
Proccessed = % 0.059
After myMap.size() = 29
Proccessed = % 0.061
After myMap.size() = 30
Proccessed = % 0.063
After myMap.size() = 31
Proccessed = % 0.065
After myMap.size() = 32
Proccessed = % 0.067
After myMap.size() = 33
它会在第34个项目突然继续运行无限时间(虽然我期望它会继续添加1第000项)。当我删除myMap.put(....)时,它会一直持续到1000;所以put函数会有一些错误。我怀疑我有一个问题(或者在对象类型的定义中缺少一个属性)。
任何人都知道我使用MapDB有什么问题吗?
答
问题是这样的:
public int compareTo(Tuple_comparable o) {
return 1;
}
我不打算在这里解释一下。首先,我会推荐HashMap,并通过IDE生成equals/hashcode。
MapDB 1.0会死锁,但在2.0中解决。所以我不认为这是一个问题。
MapDB 2.0在哪里?有没有对MapDB 1.0的解决方法? – 2014-12-30 20:06:13