08 receive task

A receiving task

Receiving task (receiveTask) i.e. waiting task, the reception task is a simple task, it waits for arrival of the corresponding message. Currently, the only official to achieve the java semantics of this task. When the process reaches the receiving task, process state is saved to the database. After the task is created, meaning that the process will enter etc. to be like state until the engine receives a particular message, which triggers the flow through the receiving task to continue.

1, a flowchart

 

 

Code:
    // Run Process
    @Test
    public void doTask() {
        RuntimeService runtimeService = this.processEngine.getRuntimeService();
        String processDefinitionKey = "myProcess";
        ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(processDefinitionKey);
        System.out.println ( "process started successfully:" + processInstance.getId ());
        
        / ** set the day sales process variables used for transmitting service parameters * /
        int value = 0; // should be to query the database, time-consuming operation summary ---
        int tryNum = 0; // attempt to consolidate the number of
        while (true) {
            Tryne ++;
            try {
                value = this.hzxx();
                break;
            } catch (Exception e) {
                e.printStackTrace ();
                if(tryNum==10) {
                    System.out.println ( "try 10 times all fail summary, the summary has been terminated.");
                    break;
                }
            }
        }
        runtimeService.setVariable (processInstance.getId (), "current sales", value);
        
        / ** execute step backwards, if the process is in a wait state, so that the flow continues * /
        runtimeService.signal(processInstance.getId());
        
        / * Get the value from the summary of the day's sales process variables * /
        Integer saleMoney = (Integer) runtimeService//
                .getVariable (processInstance.getId (), "current sales");
        System.out.println(saleMoney);
        System.out.println ( "SMS");
        Boolean flag = false;
        int num = 0;
        do {
            flag = send();
            a ++;
            if (num == 10) {
                System.out.println ( "10 times to try to send all failed, terminated sent.");
                break;
            }
        } while (!flag);

        / ** execute step backwards, if the process is in a wait state, so that the flow continues * /
        runtimeService.signal(processInstance.getId());
        System.out.println ( "Process Execution completed");
    }

    //Summary information
    public Integer hzxx() {
        // query the database
        System.out.println ( "data is summarized in ....");
        try {
            Thread.sleep(2000);
        } catch (Exception e) {
            e.printStackTrace ();
        }
        System.out.println ( "complete data summary");
        return 10000;
    }

    //send messages
    private Boolean send() {
        System.out.println ( "successfully sent");
        return true;
    }



Guess you like

Origin www.cnblogs.com/Guorisy/p/12099263.html