1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.fhw.cabaweb.webfrontend.servlets;
21
22 import java.io.IOException;
23
24 import javax.servlet.*;
25
26 import org.fhw.cabaweb.calculation.timer.BerechnungsJob;
27 import org.quartz.CronTrigger;
28 import org.quartz.JobDetail;
29 import org.quartz.Scheduler;
30 import org.quartz.SchedulerFactory;
31
32 /***
33 * Die Klasse dient als Listener für den Servlet Container um den Timer im Hintergrund laufen zu lassen.
34 *
35 * @author <a href="mailto:thomas.vogt@tvc-software.com">Thomas Vogt</a>
36 * @version Version 1.0 27.08.2004
37 */
38 public class TimerServlet implements Servlet
39 {
40
41 /***
42 * @see javax.servlet.Servlet#init(ServletConfig)
43 */
44 public void init(ServletConfig arg0) throws ServletException
45 {
46 SchedulerFactory schedFact = new org.quartz.impl.StdSchedulerFactory();
47 JobDetail jobDetail = new JobDetail("Calculation Timer", "Calculation Timer", BerechnungsJob.class);
48 CronTrigger trigger = new CronTrigger("Calculation Timer", "Calculation Timer");
49
50 try
51 {
52 trigger.setCronExpression("0 0/5 * * * ?");
53 Scheduler sched = schedFact.getScheduler();
54 sched.start();
55 sched.scheduleJob(jobDetail, trigger);
56 }
57 catch (Exception e)
58 {
59 e.printStackTrace();
60 }
61 }
62
63 /***
64 * @see javax.servlet.Servlet#getServletConfig()
65 */
66 public ServletConfig getServletConfig()
67 {
68 return null;
69 }
70
71 /***
72 * @see javax.servlet.Servlet#service(ServletRequest, ServletResponse)
73 */
74 public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException
75 {
76 }
77
78 /***
79 * @see javax.servlet.Servlet#getServletInfo()
80 */
81 public String getServletInfo()
82 {
83 return null;
84 }
85
86 /***
87 * @see javax.servlet.Servlet#destroy()
88 */
89 public void destroy()
90 {
91 }
92
93 }