Re: Need some guidance on using timer
Hendrik Maryns wrote:
....
Right now, it looks like this:
try {
testFunction1()
} catch (OutOfMemoryError e) {
System.gc();
System.out.println("OOME!");
}
try {
testFunction2()
} catch (OutOfMemoryError e) {
System.gc();
System.out.println("OOME!");
}
...
this works, since until recently, memory was the main problem in the
functions. However, I applied some nice tricks (hum), and now memory is
no longer the problem, but rather execution time. So something similar,
which, instead of waiting for an OOME, waits for X minutes, then breaks
off execution, and start the next one.
....
Here are a couple of random suggestions, completely untested:
1. Try Thread.stop. I know it is deprecated, and understand the reasons,
but if I understand the situation this is rather experimental, so it may
be worth taking a risk.
2. Run the test function in a separate Process, and call its kill method.
In both cases, you need to make sure that the test function does things
to force its progress to be visible. That is an inherent consequence of
running it in a separate thread, and killing that thread. If you force
all activity to be continuously visible to other threads, your test code
will be running artificially slowly, using main memory too much and
registers too little.
Given that need to force visibility of progress, why not just check the
time at each report point and terminate tidily when it is after a
specified limit?
Patricia