making a thread wait
This is part of a for-loop. I want to excecute some code, but want it to wait some time each time it goes through the loop. The time it needs to wait in miliseconds each time is set in "waitTimes", which is an long. I read the API of "object.wait()" and saw all kinds of errors it could throw. I don't think most of it apply in my case, but I wanted to be safe. So I build this whole construct.
} catch (InterruptedException e)
All I want it to do is make the thread wait the amount of miliseconds specified in waitTimes[i], does this code do that, or did I miss something?
I think you are looking for the sleep() method ?! :)
Just found it in the thread class, what is the differce between the wait() methode in the object class and the sleep() methode?
I did, they seem to do exactly the same. Only the wait() methode can throw more exceptions, but the sleep() methode needs to be applied on the thread, not the object. Therfore the logical choice seems to me the wait() methode.
Originally Posted by eRaaaa
Which brings me back to my original question: does my code do what I intend it to do?
The main task of this method is: "Causes the current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object" in conjunction with synchronisation and monitoring.
An alternative would be to use a timer!