OFBiz development of asynchronous services and scheduled Tasks (Job Scheduler)

Source: Internet
Author: User
Tags time limit
If you want to add a jobsandbox schedule to a Java program, you can use the
Dispatcher.schedule (
JobName, Poolname, ServiceName, Servicecontext,
StartTime, frequency, interval, count, EndTime, Maxretry
);



Webtools The actual method implementation of the new task scheduling feature, in the following location:
Org.ofbiz.webapp.event.CoreEvents.scheduleService

(HttpServletRequest request, httpservletresponse response)



parameter analysis of [Dispatcher.schedule] method

JobName: Scheduled Task name, uniquely identifying

Poolname:job Pool name If you don't know what this is, the default pool is good.

Servicename:job the name of the service to invoke

Servicecontext:map-type parameters, the job scheduler needs to use the data, will be converted into XML format saved to Runtimedata (repeated scheduling will be used again)

The start time of the Starttime:long format execution schedule

Frequency: Frequency of execution (data type has recurrencerule.daily (execution frequency in days),
Recurrencerule.hourly (frequency of execution in hours), etc.)

Interval: Perform interval mates frequency use, frequency units, interval as quantity,
Unite its XX days/times (xx days to execute once), XX hours/times (xx hours to execute once)

Count: Number of executions. The maximum number of executions that are not executed when the number of executions reaches this value. If set-1 is unlimited

EndTime: Execution end time, typically used when count is-1, is not executed when the time limit is reached

Maxretry: The number of repeated executions after a failure, the number of times a scheduled execution failed, 1 infinite, until execution succeeded



the relationship between the asynchronous service and the scheduled task
The asynchronous service runs in a separate thread and the current thread does not wait.
The invoked service will effectively start running concurrently with the service or event that invoked it.
The current service thread therefore gets no information about the asynchronous run service.
An error that occurs in an asynchronous service will not raise a failure or an error for the service or event that called it.

The asynchronous service is actually added to the job scheduler. It is the task of the service that is waiting to be called in the call queue of the job scheduler.
Below the service engine tools header. Select the job list to see the full list of tasks.
The job without start date/time (start date and time) has not yet started.
The job with end date/time (end date/time) has been completed. Run time is the time they are scheduled to run.
When you initialize the seed data execution, all the highlighted tasks in the list are added to the Jobsandbox entity.
And Recurrencerule (also an entity) information that specifies how often they are executed once.

The pool default setting for the task to run is pool. A OFBiz instance can be dedicated to perform specific tasks,
Even though the task Scheduler may run in each instance, only one instance will run the task.



how the scheduler performs scheduled Tasks
An example of the best use of the scheduler is an asynchronous service invocation.
When the asynchronous service is called, it is passed to the task dispatch queue. Create (Create Recurrenceinfo and recurrencerule entities in sequence)
Storage planning tasks (create Jobsandbox entities) and context (MAP) are serialized and stored (establishing runtimedata entities)
The scheduler finds the top task in the scheduled task queue (the asynchronous service does not have any delay time) to execute by queue.



using the example
Jobsandbox function Analysis
String jobName = "Job1"; Program Name
String poolname = "Pool"; Default mode
String serviceName = "ServiceName"; Name of the service scheduled for execution
Map Service_context = Fastmap.newinstance (); Initial data required by the service
Long startTime = System.currenttimemillis (); Start time
Long endTime = System.currenttimemillis (); End time
int frequency = 1; Frequency
int interval = 1000; Interval
int count = 1; Number
int maxretry = 3; Maximum number of retries
try {
Dispatcher.schedule (JobName, poolname, ServiceName, Service_context,
StartTime, frequency, interval, count, EndTime, maxretry);
} catch (Genericserviceexception e) {
Debug.logerror (E, E.getmessage (), module);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.