Bboss quartz timed task use case introduction

Introduction to the use case of bboss quartz timing tasks
The source code address of the demo gradle
project in this article: https://github.com/bbossgroups/quartzdemo




<dependency>
    <groupId>com.bbossgroups</groupId>
    <artifactId>bboss-schedule</artifactId>
    <version>5.0.3.5</version>
</dependency>


The gradle coordinates
compile 'com.bbossgroups:bboss-schedule:5.0.3.5'

The bboss integration quartz version is quartz 2.3.0 .

2. Define job processing tasks
package org.frameworkset.quartz.job;


/**
 * Scheduled task implementation class
 */
public class DemoJob {
    /**
     * Parameters that timed tasks need to depend on
     */
    private String jobParam ;
    private String jobParam1;
    /**
     * Scheduled task method
     */
    public void jobmethod(){
        System.out.println("execute job method:jobParam="+jobParam+",jobParam1="+jobParam);

    }
}


Timing task configuration
Add timing tasks in the bboss quartz task configuration file org/frameworkset/task/quarts-task.xml:
<!--
	task scheduling
-->
<properties>
	<!--<config file="elastic.properties"/>-->
	<!--quartz engine configuration parameters, refer to the official quartz configuration document
         
	http://www.quartz-scheduler.org/documentation/quartz-2.2.x/configuration/
first part	
-->
	<property name="quartz.config">
		<map>
			<property name="org.quartz.scheduler.instanceName" value="DefaultQuartzScheduler111" />
			<property name="org.quartz.scheduler.rmi.export" value="false" />
			<property name="org.quartz.scheduler.rmi.proxy" value="false" />
			<property name="org.quartz.scheduler.wrapJobExecutionInUserTransaction" value="false" />
			<property name="org.quartz.threadPool.class" value="org.quartz.simpl.SimpleThreadPool" />
			<property name="org.quartz.threadPool.threadCount" value="10" />
			<property name="org.quartz.threadPool.threadPriority" value="5" />
			<property name="org.quartz.threadPool.threadsInheritContextClassLoaderOfInitializingThread" value="true" />
			<property name="org.quartz.jobStore.misfireThreshold" value="6000" />
			<property name="org.quartz.jobStore.class" value="org.quartz.simpl.RAMJobStore" />
		</map>
		<!-- for cluster -->
		
	</property>
<!--Part II-->
	<property name="taskconfig" enable="true">
		<list>
			<property name="Scheduled task executor" taskid="default"
				class="org.frameworkset.task.DefaultScheduleService" used="true">
				<!--
					executable task items
					Property description:
					name: task item name
					id: task item ID
					action: a specific task execution handler that implements the org.frameworkset.task.Execute interface
					cron_time: time expression in cron format, used to manage the life cycle of task execution, please refer to the documentation of date management control quartz for related rules
					Basic format: [parameters must be separated by spaces]
					*  *  *  *  *  command
					time-sharing sun-month-week command

					The first column indicates minutes 1 to 59 with * or */1 for every minute
					The second column represents hours 1 to 23 (0 means 0 o'clock)
					The third column represents the date 1 to 31
					The fourth column represents the month 1 to 12
					The 5th column identifies the day of the week 0 to 6 (0 means Sunday)
					Column 6 Command to run
					shouldRecover: The property must be set to true in a cluster environment. After the Quartz service is stopped, it will try to resume all tasks that were not completed before it is restarted or other machines in the cluster take over the task.
					used whether to use
					true load, default
					false do not load	  
					Child element description:
					parameter: set the parameters of the task execution, name identifies the parameter name, value specifies the value of the parameter
				-->
				<list>
					<!--Configure timed tasks-->
					<property name="quartzjobdemo" jobid="quartzjobdemo"
							  bean-name="quartzjobdemo"
							  method="jobmethod"
						cronb_time="0/1 * * * * ?" used="true"
						shouldRecover="false"
						/>
				</list>
			</property>
		</list>
	</property>

	<property name="quartzjobdemo" class="org.frameworkset.quartz.job.DemoJob"
			  f:jobParam="asdff"
			  f:jobParam1="dddd"
			  />
	

</properties>

Configuration description
The configuration file contains two parts:
the first part of quartz engine parameter configuration, which will not be introduced here, you can refer to the document:
http://yin-bp.iteye.com/category/333270
The second part of the job configuration, you can define multiple job, here is a job configured with quartzjobdemo:
<property name="quartzjobdemo" jobid="quartzjobdemo"
  bean-name="quartzjobdemo"
  method="jobmethod"
cronb_time="0/1 * * * * ?" used="true "
shouldRecover="false"
/>

name and jobid are job identifiers, which are meaningful and guaranteed to be unique. bean-name specifies the bboss ioc component name of the job task implementation class, methd specifies the method name of the job, and cronb_time specifies the job The cron trigger time point, here is the method of executing the job once per second:
0/1 * * * * ?

Job component definition part, bboss ioc configuration reference document:
http://yin-bp.iteye.com/blog/1434626
<property name="quartzjobdemo" class="org.frameworkset.quartz.job.DemoJob"
			  f:jobParam="asdff"
			  f:jobParam1="dddd"
			  />


3. Debug job tasks
To debug job tasks, create a new test class with a main method in the project, and then run and debug in idea or eclipse:
import org.frameworkset.task.TaskService;

/**
 * Debug job tasks
 */
public class TestTask {
    public static void main(String[] args){
        /**
         * Start the quartz job engine
         */
        TaskService.getTaskService().startService();

    }
}

4. Publish a version that runs independently and
write a startup class:
org.frameworkset.quartz.job.Main
package org.frameworkset.quartz.job;

import org.frameworkset.task.TaskService;

/**
 * bboss microservice main program
 */
public class Main {
    public static void main(String[] args){
        //Start the timer task quartz engine
        TaskService.getTaskService().startService();
    }
}

Configure the entry class -runfiles/config.properties: #tool
main program
mainclass=org.frameworkset.quartz.job.Main




release job version based on gradle Run the command
on the command line:
gradle releaseVersion

can also release the version in idea:


after the version is released successfully , a runnable package will be generated in the project's build directory, and the job will be started:
linux: execute startup.sh
windowd: execute startup.bat

Take windows as an example:


running result:



a more specific bboss quartz application project: elasticsearch
historical data Cleanup jobs
https://github.com/bbossgroups/elktask



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326364419&siteId=291194637
Recommended