There is code like :
System.out.println("I wanna print next statement after 5 seconds");
// 5 seconds later
System.out.println("Time to show !");
How could I realize that? please give me an answer. ( // 5 seconcds later)
There is code like :
System.out.println("I wanna print next statement after 5 seconds");
// 5 seconds later
System.out.println("Time to show !");
How could I realize that? please give me an answer. ( // 5 seconcds later)
Try this one.
try {
Thread.sleep(5000);
}catch (InterruptedException ex){
ex.printStackTrace();
}
5000 milliseconds = 5 seconds
Thread.sleep is a static method telling the
current thread to sleep for N milliseconds.
Try this:
try {
Thread.sleep( 5000 );
} catch ( InterruptedException ex) { }
Thread.sleep(numberOfMilliseconds)
is the way to make the current thread wait for a given amount of time. If you need to fire off something that should be done in 5 seconds, but don't want to stall the entire application, look into TimerTask
.