Is there any chance that program may be freezing by using Random.nextInt() to much?
My program is like:
class CustomizedAction extends AbstractAction {
@Override
public void actionPerformed(ActionEvent e) {
clearEverything();
//Make a new Random instance
Random rnd = new Random();
//There is a loop that runs 6 times,
//for each time I will processing the value generated by rnd.nextInt()
for(loop 6 times) {
anArrayList = process(rnd.nextInt(), rnd.nextInt());
}
//Then I have another loop which runs for 12 times.
//For each time, I generated a number and do some comparing the
//new born with the previous generated numbers
//to try to make the numbers from list2 different with list1.
for(loop 12 times) {
int aNumber = rnd.nextInt();
while(!anArrayList.contains(aNumber)) {
aNumber = rnd.nextInt();
}
anotherArrayList.add(aNumber);
}
}
}
Sometime, the customizedAction works, but sometime, the customizedAction makes whole program freezing and all previous messages in Console which are printed out before are lost. So strange for me, because if there is something wrong with logic part, the printed messages in Console should not be lost.
The more times I run the loop, the higher chance customizedAction makes program freezing.
So, I'm wondering, does running nextInt() too much can make program freeze?
Here are the images of my program when it's freezing.
1st time try CustomizedAction. Everything is fine.
2nd time try CustomizedAction. The messages printed before in Console are lost and program is freezing.
Aucun commentaire:
Enregistrer un commentaire