You can use ScheduledExecutorService to run methods or tasks periodically in java.
Check the example below.


import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

public class BeepControlExecutor {
    public static void main(String[] args) {
        ScheduledExecutorService execService
                =  Executors.newScheduledThreadPool(5);
            //The repetitive task, say to update Database
            System.out.println("hi there at: "+ new java.util.Date());
        }, 0, 1000L, TimeUnit.MILLISECONDS);

    public static void method1(){

Leave a Reply

Your email address will not be published. Required fields are marked *

WP Facebook Auto Publish Powered By :