need to run specific functionality at specific interval in java

后端 未结 2 1313
深忆病人
深忆病人 2021-01-24 17:43

I have a specific requirement.

I have a notification functionality which sends the email to all the systems clients. The code is written in java.

What i want to

2条回答
  •  情深已故
    2021-01-24 18:21

    Why not use a ScheduledThreadPoolExecutor which allows you to schedule tasks to execute in future.

    ScheduledExecutorService scheduledExecutorService =
            Executors.newScheduledThreadPool(5);
    
    ScheduledFuture scheduledFuture =
        scheduledExecutorService.schedule(new Callable() {
            public Object call() throws Exception {
                System.out.println("Executed!");
                return "Called!";
            }
        },
        5,
        TimeUnit.SECONDS);
    

提交回复
热议问题