<?xml version="1.0" encoding="UTF-8"?> <process name="helloworld" xmlns="http://jbpm.org/4.4/jpdl"> <start name="start1" g="228,53,48,48"> <transition name="to state1" to="state1" g="-59,-17"/> </start> <state name="state1" g="208,138,92,52"> <transition name="to state2" to="state2" g="-59,-17"/> </state> <state name="state2" g="208,223,92,52"> <transition name="to end1" to="end1" g="-47,-17"/> </state> <end name="end1" g="233,308,48,48"/> </process>
ProcessEngine processEngine = Configuration.getProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); // 部署流程定义 repositoryService.createDeployment().addResourceFromClasspath("cn/jbpm/test/helloworld.jpdl.xml").deploy(); ExecutionService executionService = processEngine.getExecutionService(); // 开始流程实例 ProcessInstance processInstance = executionService.startProcessInstanceByKey("helloworld"); System.out.println(processInstance.isActive("start"));// false System.out.println(processInstance.isActive("state1"));//true System.out.println("xxxxxxxx 进入到state1 xxxxxxxxxxx"); ProcessInstance instanceState1 = executionService.signalExecutionById(processInstance.getId(),"to state2"); System.out.println(instanceState1.isActive("state1"));//false System.out.println(instanceState1.isActive("state2"));//true System.out.println("xxxxxxxx 进入到state2 xxxxxxxxxxx"); ProcessInstance instanceState2 = executionService.signalExecutionById(instanceState1.getId(),"to end1"); System.out.println(instanceState2.isActive("state2"));//false System.out.println(instanceState2.isEnded());//true