Most of the time, we imagined Activiti to join some of our own timing processes, just as they did at timed events. However, timing start events have great limitations, such as time, number of cycles, and cycle intervals that must be specified, which can not be processed for some processes that calculate time and start based on actual conditions.
Through a series of source code analysis, finally found the way to manually create a job, the code is as follows:
Time Calculation Date now = new Date ();//delay is the time variable of the current time, the date target = new Date (now.gettime () + delay * 60 * 1000);//Time Event declaration Tim erentity timer = new timerentity (); Timer.setduedate (target); Timer.setexclusive (true); Timer.setjobhandlerconfiguration ("Customprocesskey");//deposit The process required to start keytimer.setjobhandlertype ( Timerstarteventjobhandler.type);//Save Job Event Context.getcommandcontext (). Getjobentitymanager (). Schedule (timer);
The code snippet works by simply adding a record to the Act_ru_job table, but when the Activiti configuration is enabled (see Code below), the Activiti process engine triggers the specified process at the specified time.
<property name= "Jobexecutoractivate" value= "true"/>
At this point, we can manually under the control of the code, at an indeterminate time (program computing) points, start any (specify key) process, greatly facilitate the customization of process execution.
To manually create a job using the Activiti internal API (Job)