6 Ağustos 2019 Salı

Quartz

CronScheduleBuilder Sınıfı
Giriş
Şu satırı dahil ederiz.
import org.quartz.CronScheduleBuilder;
chronSchedule metodu
Şöyle yaparız.
CronScheduleBuilder.cronSchedule("0/10 * * * * ?")
QuartzInitializerListener Sınıfı
Giriş
ServletContext'e bir StdSchedulerFactory yerleştirir.

Tanımlama
Şöyle yaparız.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns="http://java.sun.com/xml/ns/javaee"
  xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
                      http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  id="WebApp_ID" version="2.5">
  <display-name>TestWebBasedQuartz</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>quartz:shutdown-on-unload</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>quartz:wait-on-shutdown</param-name>
    <param-value>true</param-value>
  </context-param>
  <context-param>
    <param-name>quartz:start-on-load</param-name>
    <param-value>true</param-value>
  </context-param>

  <listener>
    <listener-class>org.quartz.ee.servlet.QuartzInitializerListener</listener-class>
  </listener>

  <listener>
    <listener-class>com.hitesh.quartz.test.QuartzJobListener</listener-class>
  </listener>
</web-app>
QUART_FACTORY_KEY Alanı
Bu scheduler'a erişmek için ServletContext ile şöyle yaparız.
StdSchedulerFactory factory = (StdSchedulerFactory) ctx
  .getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY);
HttpServletRequest ile şöyle yaparız.
StdSchedulerFactory factory = (StdSchedulerFactory)httpServletRequest
  .getServletContext()
  .getAttribute(QuartzInitializerListener.QUARTZ_FACTORY_KEY);

Hiç yorum yok:

Yorum Gönder