我正在尝试使用limitFilter从缓存中检索结果:
class Student {
long studentId;
}
class StudentComparator implements Comparator<Student> {
public int compare(Student o1, Student o2) {
return o1.getStudentId() - o2.getStudentId();
}
}
StudentComparator studentComparator = new StudentComparator();
EntryComparator comparator = new EntryComparator(studentComparator,EntryComparator.CMP_VALUE);
LimitFilter limitFilter = new LimitFilter(AlwaysFilter.INSTANCE, 5)
limitFilter.setComparator(comparator);
Set studentSet = null;
do {
studentSet = studentCache.entrySet(limitFilter);
.....
// print the set
.....
limitFilter.nextPage();
} while (studentSet.size() > 0)根据API
public void setComparator(Comparator comparator) : Set the Comparator
used to partition the values into pages. 因此,我期望limitfilter会使用比较器对数据进行排序,但它似乎没有这样做。例如,我有20个学生,studentId的范围从1到20。我希望有4个studentSet的do/while循环的范围分别为: 1-5,6-10,11-15,16-20。但是有时在第一个studentSet中有一个Id为13的学生,或者在最后一个studentSet中有一个Id为2的学生,等等。
如果有人遇到这个问题,请告诉我你的想法。
发布于 2016-10-20 20:48:35
根据LimitFilter.setComparator(Comparator comparator)的JavaDoc (至少对于Coherence 12.2.1 )
此方法仅供查询处理器使用。客户端不应修改此属性的内容。
要获得所描述的结果,您应该调用(在循环中):
studentSet = studentCache.entrySet(limitFilter, comparator);https://stackoverflow.com/questions/34449348
复制相似问题