데이터베이스 필드를 매일 확인하려면 어떻게 해야 합니까? 크론 작업? (How can I check database field every day?Cron job?)


문제 설명

데이터베이스 필드를 매일 확인하려면 어떻게 해야 합니까? 크론 작업? (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!


참조 솔루션

방법 1:

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. 

방법 2:

Use either TimerTask or ScheduledTask. Here is a good tutorial for that:

http://www.ibm.com/developerworks/java/library/j‑schedule/index.html

방법 3:

Instead of saving an attribute for the contract not being valid, and having to check it against sysdate every day, I would use a predicate such as "access_date < trunc(sysdate)" to find expired contracts, and an expression such as:

case when access_date < trunc(sysdate) then 'N' else 'Y' end

... to display whether a contract is active or not.

(by MainstreamDeveloper00goblinjuiceJuned AhsanDavid Aldridge)

참조 문서

  1. How can I check database field every day?Cron job? (CC BY‑SA 3.0/4.0)

#jakarta-ee #oracle #sqlite #cron-task #java






관련 질문

주입을 통해 JBoss AS의 다른 WAR에서 EJB에 액세스 (Access EJB from different WAR in JBoss AS via injection)

데이터베이스 필드를 매일 확인하려면 어떻게 해야 합니까? 크론 작업? (How can I check database field every day?Cron job?)

Java ee netbeans에서 javadocs를 첨부하는 방법 (How to attach javadocs in java ee netbeans)

날짜 차이 제한 최대 절전 모드 (Date difference in days Restriction Hibernate)

Wildfly 8.2.1에서 EJB 2.1에 액세스할 때 ClassCastException이 발생하는 이유는 무엇입니까? (Why I am getting ClassCastException when accessing EJB 2.1 in Wildfly 8.2.1?)

WebLogic Application Server(10.3.6)가 큰 크기의 이어 파일 배포, 중요한 CSRF로 실패함 (WebLogic Application Server (10.3.6) fails with Large sized ear file deployment, critical CSRF)

개체 배열을 설정하는 동안 FindBug 오류 '변경 가능한 개체에 대한 참조를 통합하여 내부 표현을 노출할 수 있음'을 수정하는 방법은 무엇입니까? (How to Fix FindBug error 'May expose internal representation by incorporating reference to mutable object' while setting Array of Objects?)

Stateless EJB가 역직렬화될 때 @Resource 주석이 적용됩니까? (Is the @Resource annotation applied when a Stateless EJB is deserialized?)

Eclipse 및 웹 프로젝트 가져오기, 서버에서 실행 누락! (Eclipse and Web Project import, run on Server missing!)

Spring 다중 모듈 프로젝트를 설정하는 방법은 무엇입니까? (How to setup a Spring multimodule project?)

JBoss 5.1의 Java EE 빈에서 빈 EntityManager (Empty EntityManager in Java EE bean on JBoss 5.1)

사용자가 찾을 수 없는 페이지를 요청했는지 감지하는 필터를 만드는 방법은 무엇입니까? (How to make a filter to detect if the user requested a page that is not found?)







코멘트