A simple problem
I am facing a simple problem i think... i just want to know how i can just wait 10 seconds in java....I mean how can i run a method for a predefined amount of time after that i want to stop executing that function... Is there a way? Lets suppose i want to run xx.begin() for 10 seconds after that i want to call xx.stop();
Try with this code snippet.
Specify parameter( time- in milliseconds).
public void waitMethod(long timeLimit){
long currTime = System.currentTimeMillis();
long limitTime = currTime + timeLimit;
while (true){
if (System.currentTimeMillis() > limitTime)
break;
}
}
Cheers,
Satish Patil
This looping is good if there is someting do in the loop (left out from this example). Otherwise it is busy-waiting, a Bad Thing (tm), it wastes resources. Cf. Thread.sleep.