Let's say I have this code:
public class helloworld
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
Using threads, is there a way I can make Hello world echo continuously every 5 seconds?
check out
http://download.oracle.com/javase/tutorial/essential/concurrency/sleep.html
it is doing what you want to do. basically do the print in a while loop, and after the print do a
Using ScheduledExecutorService:
This version repeats the hello world message continuously, while allowing the user to terminate the message-writing thread:
How about this?
Easiest way would be
But you should probably use the Timer and TimerTask classes instead available through the java.concurrency package.