Thread
slow down by interspersing it with calls to the Thread.sleep(ms)
method. ms
is the number of milliseconds you want the thread to wait before proceeding on. There are one thousand milliseconds in a second.
The sleep()
method throws InterruptedException
s. Therefore when you put a thread to sleep, you need to catch InterruptedException
s. Thus every call to sleep()
should be wrapped in a try catch
block like this:
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
}
To delay a program for a fixed amount of time
you often do something like this:
try {
Thread.sleep(1000);
}
catch (InterruptedException e) {
}