In my application I'm using timeouts to exit out of certain endless loops if it is uncertain if the condition will be met in reasonable time.
For the timekeeping I'm using the system's time since it's straightforward:
public class BenchmarkTimer
{
private long startTime;
public BenchmarkTimer()
{
startTime = System.currentTimeMillis();
}
public boolean isExpired(long milliseconds)
{
long executionTime = currentTimeMillis() - startTime;
return executionTime > milliseconds;
}
}
However, when debugging, I don't want the time to continue while the application is frozen. This obviously doesn't work by default since the system time will continue even during breakpoints. I don't want to run into a timeout due to me taking too long on a breakpoint to continue because under normal application execution this would behave differently (e.g. it would execute more tries before "giving up").
Is there any kind of solution to this problem? Can IntelliJ IDEA
halt the system time visible to the Java application only during breakpoints? I want debugging to behave like a regular execution including the timeouts so I'm not sure how to accomplish this in general.