Reputation: 121
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
Reputation: 15698
You can also try this
try {
TimeUnit.SECONDS.sleep(1);
} catch (InterruptedException e) {
e.printStackTrace();
}
Upvotes: 2
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