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();

[329 byte] By [dare-devila] at [2007-11-27 1:05:23]
# 1
Hi, See Thread, Timer and RunnableHope that help.Jack
jack@square6a at 2007-7-11 23:40:30 > top of Java-index,Java Essentials,Java Programming...
# 2

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

Satish_Patila at 2007-7-11 23:40:30 > top of Java-index,Java Essentials,Java Programming...
# 3
thanks man....
dare-devila at 2007-7-11 23:40:30 > top of Java-index,Java Essentials,Java Programming...
# 4
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.
BIJ001a at 2007-7-11 23:40:30 > top of Java-index,Java Essentials,Java Programming...