Search code examples
javascheduled-tasks

Can you execute a task repeatedly in Java?


Is it possible to repeatedly execute a task each day, each minute, each second, each year? I want it to run like a daemon.

I need a scheduled task to search the database continuously; if it finds a certain value then it should execute a further task.


Solution

  • I want to ask whether it is possible to repeatedly

    You can use a loop, or a ScheduleExecutorService, or a Timer, or Quartz.

    each day each minute each second each year

    So once a second.

    I want it to run like a daemon.

    I would just make it a daemon thread then. No need to make it "like" a daemon.

    if it find the correct value then it should do the remaining task.

    Simple enough.

    Read the data, check the value and if its what you want do the rest.