activiti总结2

根据流程号查询失败原因。

activiti重试机制。齿轮节点、邮件节点、任务节点。ACT_HI_ACTINST历史表。ACT_RU_EXECUTION运行表。看图。

在Eclipse里面自己写个测试方法(main方法,或者junit Test方法)。可以暂时不用管activiti页面上操作的丰富的内容。通过这种方式,在每个结点加上Sleep(60)方法。这样就可以在mysql数据库的act_ru_execution表跟踪到内容。

下面是不使用spring容器的测试activiti的方法。(activitiGuide_NoSpringEnvironment)

/**
 * 
 */
package main;

import java.util.List;

import org.apache.ibatis.type.TypeHandler;
import org.activiti.engine.HistoryService;
import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngineConfiguration;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.history.HistoricProcessInstance;
import org.activiti.engine.task.Task;

/**
 * @author Administrator
 *
 */
public class TenMinuteTutorial {
      
      public static void main(String[] args) {
        
        // Create Activiti process engine
        ProcessEngine processEngine = ProcessEngineConfiguration
          .createStandaloneProcessEngineConfiguration()
          .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_TRUE)
          .setJdbcDriver("com.mysql.jdbc.Driver")
                  .setJdbcUrl("jdbc:mysql://localhost:3306/activiti")
                  .setJdbcUsername("root")
                  .setJdbcPassword("")
                  .setJobExecutorActivate(false)//ture和false有什么区别
          .buildProcessEngine();
          /*ProcessEngine processEngine = ProcessEngineConfiguration.createStandaloneInMemProcessEngineConfiguration()
                  .setDatabaseSchemaUpdate(ProcessEngineConfiguration.DB_SCHEMA_UPDATE_FALSE)
                  .setJdbcUrl("jdbc:h2:mem:my-own-db;DB_CLOSE_DELAY=1000")
                  .setJobExecutorActivate(true)
                  .buildProcessEngine();*/
          //ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
        // Get Activiti services
        RepositoryService repositoryService = processEngine.getRepositoryService();
        RuntimeService runtimeService = processEngine.getRuntimeService();
        
        // Deploy the process definition
        repositoryService.createDeployment()
          .addClasspathResource("resource/FinancialReportProcess.bpmn20.xml")
          .deploy();
        
        // Start a process instance
        String procId = runtimeService.startProcessInstanceByKey("financialReport").getId();
        
        // Get the first task
        TaskService taskService = processEngine.getTaskService();
        List<Task> tasks = taskService.createTaskQuery().taskCandidateGroup("accountancy").list();
        for (Task task : tasks) {
          System.out.println("Following task is available for accountancy group: " + task.getName());
          
          // claim it
          taskService.claim(task.getId(), "fozzie");
        }
        
        // Verify Fozzie can now retrieve the task
        tasks = taskService.createTaskQuery().taskAssignee("fozzie").list();
        for (Task task : tasks) {
          System.out.println("Task for fozzie: " + task.getName());
          
          // Complete the task
          taskService.complete(task.getId());
        }
        
        System.out.println("Number of tasks for fozzie: " 
                + taskService.createTaskQuery().taskAssignee("fozzie").count());
        
        // Retrieve and claim the second task
        tasks = taskService.createTaskQuery().taskCandidateGroup("management").list();
        for (Task task : tasks) {
          System.out.println("Following task is available for accountancy group: " + task.getName());
          taskService.claim(task.getId(), "kermit");
        }
        
        // Completing the second task ends the process
        for (Task task : tasks) {
          taskService.complete(task.getId());
        }
        
        // verify that the process is actually finished
        HistoryService historyService = processEngine.getHistoryService();
        HistoricProcessInstance historicProcessInstance = 
          historyService.createHistoricProcessInstanceQuery().processInstanceId(procId).singleResult();
        System.out.println("Process instance end time: " + historicProcessInstance.getEndTime());
      }

    }

 

 .setJobExecutorActivate(false)//ture和false有什么区别

 

采用spring容器的方式。ProcessEngine processEngine =ProcessEngines.getDefaultProcessEngine();这行代码会自动寻找activiti.cfg.xml

activiti.cfg.xml里面配置的bean的id为<beanid="processEngineConfiguration",有许多类可以用来定义这个processEngineConfiguration。那么spring容器用哪个类?

org.activiti.engine.impl.cfg.StandaloneProcessEngineConfiguration

org.activiti.engine.impl.cfg.StandaloneInMemProcessEngineConfiguration

org.activiti.spring.SpringProcessEngineConfiguration 这个专用于spring环境,其他的类不知道能不能用于spring环境。需要验证。

org.activiti.engine.impl.cfg.JtaProcessEngineConfiguration

 

如果activiti执行出现异常,会导致以下情况:

act_ru_task表出现多条数据,如下:

1007    1    1004    1004    simpleProcess:3:1003    Write monthly financial report        Write monthly financial report for publication to shareholders.    writeReportTask                50    2013-10-05 11:49:28    
1107    1    1104    1104    simpleProcess:4:1103    Write monthly financial report        Write monthly financial report for publication to shareholders.    writeReportTask                50    2013-10-05 11:50:03    
807    1    804    804    simpleProcess:1:803    Write monthly financial report        Write monthly financial report for publication to shareholders.    writeReportTask                50    2013-10-05 11:47:53    
907    1    904    904    simpleProcess:2:903    Write monthly financial report        Write monthly financial report for publication to shareholders.    writeReportTask                50    2013-10-05 11:48:43    

导致Task task = taskService.createTaskQuery().singleResult();出错,因为查询出来不是一条记录。

正常情况如果执行完成,这张表产生的数据会被清空。出现异常时,数据没有清空。activiti的异常处理机制没有清空数据,不知道是不是activiti的缺陷(不足),是做不到还是没有做到。

 

深刻理解This will look for an activiti.cfg.xml file on the classpath中的classpath,这个路径对应Eclipse的Build path =》Source=》Default output folder(比如activiti_SpringEnvironment/bin目录),将activiti-context.xml

和activiti.cfg.xml文件。

posted @ 2013-09-05 18:38  唾手可得的树  阅读(768)  评论(0编辑  收藏  举报