Thread.sleep(). I finally get it. Thread.sleep() is a static method. You can call it on any thread you like, as you have, but what will sleep is the current thread, the one that called the method, not the one you called it on, unless they are the same, which in your code they don't seem to be.
Class A extends Thread{
public void run(){
while(true){
doLongProcess();
Thread.sleep(1000);
}
}
}
What happens here is ...the doLongProcess() executes. On Thread.sleep, the main thread, which is Class A sleeps...for that time. and then the processing continues...since you have while(true).
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment