Unskilled Unskilled - 1 year ago 78
Java Question

Java how to wait before going on

I want my runnable to wait a couple of seconds before starting again, any advice on how to do this?

if i use this.wait(); it doesn't work because that stops everthing in my program and i just want the runnable to pause.

Answer Source

Here is an example for 2 second delayed Runnable

final Handler handler = new Handler();
final Runnable runnable = new Runnable() {
    public void run() {
        // Do stuff

        handler.postDelayed(this, 2000);

handler.postDelayed(runnable, 2000);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download