Quartz di JAVA Web

Bisa dibilang ini lanjutan tulisan tentang quartz, g ribet, Cuma menurut gw sih penting. Soalnya potensi untuk terus dipake cukup gede, dimana bisa dipake untuk back-end aplikasi web.
Intinya, sebenarnya gimana make quartz diintegrasiin sama JAVA Web, mungkin solusi lain ya kita bikin aplikasi terpisah pake quartz, Cuma kebetulan lagi proyek yang desain back end nya otomatis jalan pas JAVA Web nya running.

Teknologi yang digunakan:

  • Eclipse Indigo
  • JAVA 7 Update 79
  • Quartz 2.2.3

Jar yang digunakan:

  • c3p0-0.9.1.1.jar
  • log4j-1.2.16.jar
  • quartz-2.2.3.jar
  • quartz-jobs-2.2.3.jar
  • slf4j-api-1.7.7.jar
  • slf4j-log4j12-1.7.7.jar
  • jta-1.1.jar –> ini googling sendiri ya.

Web.xml

<?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_3_0.xsd"
	id="WebApp_ID" version="3.0">
	<display-name>SampleQuartzJavaWeb</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>
 
	<listener>
		<listener-class>org.quartz.ee.servlet.QuartzInitializerListener</listener-class>
	</listener>
</web-app>

Quartz.properties

# Generic configuration - probably not needed, most of this is just the defaults
org.quartz.scheduler.instanceName = MyScheduler
org.quartz.scheduler.instanceId = 1
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 1
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
 
# Configure it to look in the quartz.xml for the job schedules
org.quartz.plugin.jobInitializer.class = org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = quartz.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true
org.quartz.plugin.jobInitializer.scanInterval = 120

Quartz.xml

<?xml version="1.0" encoding="UTF-8"?>
<job-scheduling-data
	xmlns="http://www.quartz-scheduler.org/xml/JobSchedulingData"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.quartz-scheduler.org/xml/JobSchedulingData http://www.quartz-scheduler.org/xml/job_scheduling_data_1_8.xsd"
	version="1.8">
	<pre-processing-commands>
		<delete-jobs-in-group>*</delete-jobs-in-group>
		<delete-triggers-in-group>*</delete-triggers-in-group>
	</pre-processing-commands>
	<processing-directives>
		<overwrite-existing-data>true</overwrite-existing-data>
		<ignore-duplicates>false</ignore-duplicates>
	</processing-directives>
	<schedule>
		<job>
			<name>MyJob</name>
			<job-class>sample.quartz.SampleQuartzScheduler</job-class>
		</job>
		<trigger>
			<simple>
				<name>TenSecondIntervals</name>
				<job-name>MyJob</job-name>
				<repeat-count>-1</repeat-count>
				<repeat-interval>10000</repeat-interval>
			</simple>
		</trigger>
	</schedule>
</job-scheduling-data>

Contoh Class untuk job quartz

package sample.quartz;
 
import org.quartz.*;
 
public class SampleQuartzScheduler implements Job {
	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		System.out.println("Sample Quartz Scheduler");		
	}
}

Untuk detail konfigurasi quartz nya, langsung ke website resminya aja kali ya :).

Marifnst, 2016-06-05

Leave a Reply

Your email address will not be published. Required fields are marked *

Afiseaza emoticoanele Locco.Ro