Search code examples
javaoracle-databasesqlitejakarta-eecron-task

How can I check database field every day?Cron job?


I' m developing application in Java which is connected to database (Oracle or SQLite). In database I store contracts. The contract has field access_date. And i want to check this field once every day and if one day access_date will be equal to the current date then mark the contract as not valid. How can I implement this? In PHP as far as I know there are cron jobs for such tasks but what about java or java ee? How can I do this?Thanks in advance!


Solution

  • You can do this in two ways:

    1. You can use Cron to invoke a Java program at specific time (in your case, one every day).
    2. If your Java program is designed to run as service/daemon (staying in the background all the time), you can use a job scheduler such as Quartz Scheduler to invoke a certain check function at specific time.
    3. As an extension of 2., you can use ScheduledExecutorService.