need to run specific functionality at specific interval in java

后端 未结 2 1293
深忆病人
深忆病人 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);
    
    0 讨论(0)
  • 2021-01-24 18:29

    use scheduling and take a look here

    0 讨论(0)
提交回复
热议问题