forked from Fascinated/Bat
28 lines
650 B
Java
28 lines
650 B
Java
|
package cc.fascinated.bat.common;
|
||
|
|
||
|
import lombok.experimental.UtilityClass;
|
||
|
|
||
|
import java.util.Timer;
|
||
|
import java.util.TimerTask;
|
||
|
|
||
|
/**
|
||
|
* @author Fascinated (fascinated7)
|
||
|
*/
|
||
|
@UtilityClass
|
||
|
public class TimerUtils {
|
||
|
/**
|
||
|
* Runs a repeating task on a schedule
|
||
|
*
|
||
|
* @param runnable the task to run
|
||
|
* @param delay the delay before the task runs
|
||
|
*/
|
||
|
public static void scheduleRepeating(Runnable runnable, long delay, long period) {
|
||
|
new Timer().scheduleAtFixedRate(new TimerTask() {
|
||
|
@Override
|
||
|
public void run() {
|
||
|
runnable.run();
|
||
|
}
|
||
|
}, delay, period);
|
||
|
}
|
||
|
}
|