모니터 인 터 페 이 스 를 이용 하여 자바 의 정시 기능 을 실현 합 니 다.
우선 servlet 모니터 구현
public class MyListener implements ServletContextListener {
private Timer timer = null;
public void contextInitialized(ServletContextEvent servletContextEvent) {
timer = new Timer(true);
// : , : , : ( )
timer.schedule(new MyTask(), 0, 86400000);
}
public void contextDestroyed(ServletContextEvent servletContextEvent) {
timer.cancel();
}
}
그 다음 에 구체 적 인 임무 유형 을 실현 한다.
public class MyTask extends TimerTask {
public void run() {
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
sdf.format(date);
String currentTime = sdf.format(date);
if(currentTime.split("-")[2].equals("01")) {
doSomeThing();
}
}
private void doSomeThing() {
//To change body of created methods use File | Settings | File Templates.
}
}
마지막 으로 웹 xml 설정
<listener>
<listener-class>time.MyListener</listener-class>
</listener>
매일 한 번 씩 검사 하 라 고 하 세 요. 매달 1 일 인지, 보고 서 를 만 드 는 것 입 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Is Eclipse IDE dying?In 2014 the Eclipse IDE is the leading development environment for Java with a market share of approximately 65%. but ac...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.