Hi all, I have a question and any suggestions for solutions would be
greatly appreciated.
In my program, I first defined a variable called 'incidence' which has
to be updated at every time step,
public static int incidence = 0;
Then I have a method which is called 'step()' and inside 'incidence' is
updated.
public void step() {
updateIncidence();
}
......
I have another method called 'stepReport()' which writes the
'incidence' into a file.
public void stepReport() {
System.out.printf(" %d infected ( inside stepReport).\n", incidence
);
s += String.format(" %d", incidence );
}
......
I am interested in keeping the variable 'incidence' initialized and
updated at every tick count and thought it worked well. Because If I
see the output from the 'updateIndence(); method', then the output is
congruent with all the other outputs.
But the problem happens when I tried to write the variable 'incidence'
into a file. It is not updated every tick count. the incidence value
inside the method, 'stepReport()' doesn't match
that inside the 'partnerInfection( nodeList );'
So I incorporated a print method inside the 'stepReport()' and the
result is
0 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
2 infected.(inside updateIncidence)
2 infected ( inside stepReport).
2 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
1 infected.(inside updateIncidence)
1 infected ( inside stepReport).
0 infected.(inside updateIncidence)
0 infected.(inside updateIncidence)
0 infected ( inside stepReport).
So it seems that sometimes, 'stepReport()' method is executed first and
then 'updateIncidence()' is executed. But other times, the opposite.
If it would work, those two methods have to be in same order over
time.
Is there any way to control the order in which the methods are excuted
?
Any suggestions would be appreciated.
Thank you.