What is the easiest way to have a piece of Java code scheduled at a given rate ?
while (true) {
thread.sleep(1000)
method();
}
In many cases there will be better alternatives. But this is the easiest way to implement a regular execution of your method() at an interval of 1000ms + n (where n is the amount of time spent executing method())
Of course instead of 1000, you can put any millisecond value you desire. It could also be an idea to implement the while loop on a flag that another thread controls; so that there is an way to stop execution of the loop without having to kill the program.