Hi, I make a full binary tree of 4095 node, I check the first 9 node, but the root cost 24 seconds, why?
Result:
===========
find time @ 24.125000
getSons time @ 0.000000
1 : type:Nodes, sons:2
child : 2
child : 3
Iterator time @ 0.000000
find time @ 0.000000
getSons time @ 0.000000
2 : type:Nodes, sons:2
child : 4
child : 5
Iterator time @ 0.000000
find time @ 0.000000
getSons time @ 0.000000
3 : type:Nodes, sons:2
child : 6
child : 7
Iterator time @ 0.000000
find time @ 0.000000
getSons time @ 0.000000
4 : type:Nodes, sons:2
child : 8
child : 9
Iterator time @ 0.000000
find time @ 0.000000
getSons time @ 0.000000
5 : type:Nodes, sons:2
child : 10
child : 11
Iterator time @ 0.000000
find time @ 0.000000
getSons time @ 0.000000
6 : type:Nodes, sons:2
child : 12
child : 13
Iterator time @ 0.000000
find time @ 0.000000
getSons time @ 0.000000
7 : type:Nodes, sons:2
child : 14
child : 15
Iterator time @ 0.000000
find time @ 0.000000
getSons time @ 0.000000
8 : type:Nodes, sons:2
child : 16
child : 17
Iterator time @ 0.000000
find time @ 0.000000
getSons time @ 0.000000
9 : type:Nodes, sons:2
child : 18
child : 19
Iterator time @ 0.000000
The sum : 18
Class of Nodes:
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
// Success for Inheritance Sonsection
//@Cache(size=10000)
@DiscriminatorColumn(discriminatorType=DiscriminatorType.INTEGER,name="type")
@DiscriminatorValue(value="0")
public class Nodes {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int id;
@ManyToOne
@JoinColumn(name="parent")
protected Nodes parent;
@OneToMany(mappedBy="parent",fetch=FetchType.EAGER)
protected List<Nodes> Sons;
function of checking:
private static void getSons0() {
System.out.printf("===========%n");
int iSum = 0;
for (int i=0;i<3*iBlock;i++){
long start = System.currentTimeMillis();
Nodes o = em.find(Nodes.class, i+1);
System.out.printf("find time @ %f %n", (System.currentTimeMillis()-start)/1000f);
if (null== o){
System.out.printf("%s is not Nodes %n", o);
continue;
}
em.refresh(o);
start = System.currentTimeMillis();
List<Nodes> sons = o.getSons();
System.out.printf("getSons time @ %f %n", (System.currentTimeMillis()-start)/1000f);
if (null==sons) continue;
int iCnt = sons.size();
System.out.printf("%d : type:Nodes, sons:%d %n",i+1, iCnt);
iSum += iCnt;
start = System.currentTimeMillis();
Iterator<Nodes> it = sons.iterator();
while (it.hasNext()){
Nodes en = it.next();
System.out.printf("child : %d %n", en.getId());
}
System.out.printf("Iterator time @ %f %n", (System.currentTimeMillis()-start)/1000f);
}
System.out.printf("The sum : %d %n", iSum);
System.out.println();
}