user3549340
user3549340

Reputation: 121

A way to pause a method for 1 second

I'm doing a console application with Java. I have one method where I need to wait one second, then continue with my method. It's just a simple method, so it means there is no thread involved. What can I do?

My Program looks like this:

It has to wait 1 second!

Upvotes: 1

Views: 13858

Answers (2)

sol4me
sol4me

Reputation: 15698

You can also try this

    try {
        TimeUnit.SECONDS.sleep(1);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }

Upvotes: 2

Semih Eker
Semih Eker

Reputation: 2409

Try this to pause for 1 second;

try {
    Thread.sleep(1000);                 //1000 milliseconds is one second.
} catch(InterruptedException ex) {
    Thread.currentThread().interrupt();
}

Upvotes: 7

Related Questions