How to use timer to monitor lengthy loop progress
Hi,
I have a long process that iterates through a large data set and I need to monitor its progress.
Right now it's something like:
Read recordSet
for (...index++) {
... process record[index];
if (index modulus 500 = 0) {log to stdout}
}
I'm using stdout since that's where the output from the Garbage Collector is gathered, so I can check how the loop is behaving memory-wise.
In other languages I'd use a timer instead of the ugly 'if (...' but I am quite new and lost in Java, and I have been unable to find any suitable examples.
How can I use a timer in this context so that the logging is triggered each 30s, for instance? The loop might run for a veeery long time (20-60 minutes).
I understand that this would require (at least!):
- Setting up the timer
- Starting the loop
- Getting some info about the loop status, in the timer callback
- Shutting down/Killing the timer when the loop ends (or fails...)
Can anyone help?
Thanks to all.