Say I have a method called doSomething, and I call the method like this:
int result = doSomething();
And suppose doSomething() takes 500ms to execute by default. However, I want to halt the execution of doSomething() if it goes over the limit of 300ms. Would it be possible to do that in Java?
I tried the following which didn't work:
int res;
long timestart = System.currentTimeMillis();
long timeend = timestart + 30;
while(System.currentTimeMillis() < timeend) {
res = doSomething();
}