cancel
Showing results for 
Search instead for 
Did you mean: 

Local Task Variable and Global Variable

piyush_kaizen
Champ in-the-making
Champ in-the-making
What is difference between Local Task Variable and Global Task Variable .
I have understood difference between Local Process Variable and Global Process Variable as
If I set local process variable then It will not be visible on Parent process.
Please correct me if I am wrong .

Also does Parallel Gateway and Inclusive Gateway start child processes ?
Also How do i create Service Task Variables ( Local and Global ) ?
6 REPLIES 6

martin_grofcik
Confirmed Champ
Confirmed Champ
Hi Piyush,

see org.activiti.engine.test.api.task.TaskVariablesTest#testTaskExecutionVariables in activiti source.

Regards
Martin

warper
Star Contributor
Star Contributor
does Parallel Gateway and Inclusive Gateway start child processes
They start executions, not processes. Executions will share global process variables, but will have separate local process variables.

If I set local process variable then It will not be visible on Parent process.
It depends… Sub-process and call activity both create subprocesses, but sub-process (in the same process diagram) generally has access to process variables, while sub-process in call activity does not.
Nevertheless, any process can query engine for any other process variables if you derive proper helper code. It's not convenient though.

piyush_kaizen
Champ in-the-making
Champ in-the-making
Hi Warper,
Thank you for
They start executions, not processes. Executions will share global process variables, but will have separate local process variables

If i call execution.getParentId() I always get the process instance Id.
Consider the following process ( attached ).

I want to access the execution Id of Script Task 2 in execution of Script Task 4.
When I call execution execution.getParentId() I get root execution id but I want immediate parent execution id.

warper
Star Contributor
Star Contributor
Hi Piyush!
All your tasks in upper part are exclusive and synchronous. So activiti will be able to reuse execution for script task 2 and script task 4.


10:07:34 INFO  [ActivityEventListener:125] >>> START: Test 1 Process(testProcess1) VARS: {}
5scripttask1Script Task 1
8scripttask2Script Task 2
8scripttask4Script Task 4
13scripttask3Script Task 3
8scripttask5Script Task 5
10:07:34 INFO  [ActivityEventListener:98] <<< END: Test 1 Process(testProcess1) VARS: {}

If you add this to Script Task 2

        execution.setVariable("scriptTask2_proc_var", "sct2");
        execution.setVariableLocal("scriptTask2_local_var", "sct2l");</script>
and this to Script Task 4:

        java.lang.System.out.println("scriptTask2_proc_var="+execution.getVariable("scriptTask2_proc_var"));
        java.lang.System.out.println("scriptTask2_local_var="+execution.getVariableLocal("scriptTask2_local_var"));</script>
you'll see that script task 4 currently can use local variable from script task 2. It can change if you add asynchronous steps or process will be rerun from previous asynchronous step on fail retry etc.

In general it's hard to say what execution run what activity(task), there could be many of them (or none). Nevertheless you can be sure that one synchronous part of process is done in one execution.
Also  if you use only "exclusive" steps in your process, there is no need to mess with local variables.

piyush_kaizen
Champ in-the-making
Champ in-the-making
Hi Warper,
Thank you.

I have marked exclusive gateways as parallel but exclusive. ( XML Attached)
I don't completely understand it's effect on Execution creation and execution.getParentId()
Also is there a difference between marking exclusive gateway and some service task/ user task as asynchronous.

Would be glad if you can explain or point me to a resource which can explain execution creation behavior on Asynchronous activities and Asynchronous gateways.

Coming straight to the problem I need a way to pass data from 1 Activity to next Activity.
I can not rely on setting the data as process variable as Process's Activities may be asynchronous.
I can store them with Activity Name as key but there might be issues if the process diagram contains Cycles which are executing in parallel.

I have tried implementing ExecutionListener which execute on Take event but I can not access previous activities execution.
By previous Activity I mean activity which has sequence flow to current activity which caused current Activity's execution.
I also could not understand execution.getParentId() behavior.

If you can explain that behavior or point me to some resource It would be a great help.

Following is the sequence of Activity Execution

Current Activity : Start Current Activity ID : startevent1 Execution ID : 10005 Execution Parent ID : null Execution Super ID : null
Current Activity : Script Task 1 Current Activity ID : scripttask1 Execution ID : 10005 Execution Parent ID : null Execution Super ID : null
Current Activity : Parallel Gateway 1 Current Activity ID : parallelgateway1 Execution ID : 10010 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : Script Task 2 Current Activity ID : scripttask2 Execution ID : 10010 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : Parallel Gateway 1 Current Activity ID : parallelgateway1 Execution ID : 10011 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : User Task 1 Current Activity ID : usertask1 Execution ID : 10011 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : Parallel Gateway 2 Current Activity ID : parallelgateway2 Execution ID : 10010 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : Script Task 3 Current Activity ID : scripttask3 Execution ID : 10010 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : Parallel Gateway 2 Current Activity ID : parallelgateway2 Execution ID : 10019 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : Script Task 4 Current Activity ID : scripttask4 Execution ID : 10019 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : Not Parallel Gateway 2 Current Activity ID : parallelgateway3 Execution ID : 10010 Execution Parent ID : 10005 Execution Super ID : null
Current Activity : Script Task 5 Current Activity ID : scripttask5 Execution ID : 10005 Execution Parent ID : null Execution Super ID : null


Why 2 separate execution are created in case of parallel gateway 1 but Only 1 new execution created in case of parallel gateway 2 ?
Also I was expecting Script Task 3 execution's parent  to be Script Task 2's execution but this is not the case.

warper
Star Contributor
Star Contributor
Hi Piyush!
>I have marked exclusive gateways as parallel but exclusive. ( XML Attached)
>I don't completely understand it's effect on Execution creation and execution.getParentId()
Exclusive flag "locks" the whole process. That is, if you have few exclusive executions in process, only one of them will work at the same time. If activiti can reuse current execution, it will do work sequentially, it generally happens on exclusive multi-instance nodes.

>Also is there a difference between marking exclusive gateway and some service task/ user task as asynchronous.
Activiti engine executes external (actually, asynchronous) calls like startProcessByKey, signalEventReceived, and asynchronous jobs. For start/signal activiti uses current calling thread, for jobs it uses executor pool thread.
Each unit of work starts with asynchronous call/job and ends when current executing thread reaches asynchronous point on each path of execution.

>Would be glad if you can explain or point me to a resource which can explain execution creation behavior on Asynchronous activities and Asynchronous gateways.
Essential part of execution creation is explained in activiti user guide in 8.7. Transactions and Concurrency and 18. Advanced section.
Logically you can create as many executions and you want - through parallel/inclusive gateways or multi-instances, but as far as there is no parallel executions created, all the work is done in one single thread that started current unit of work.
I know of only one directly parallel possibility - multiInstance with sequential=false (and exclusive=false). The rest of capabilities either is asynchronous (for example, timerCatchingEvent is always asynchronous) or non-parallel by itself.

>Coming straight to the problem I need a way to pass data from 1 Activity to next Activity.
>I can not rely on setting the data as process variable as Process's Activities may be asynchronous.
Simple way - use call activity. Subprocess will have its own variables set, you'll have to pass essential variables to/from call activity, but input/output parameters mapping works good. Subprocess can do its work in several asynchronous parts, that's not a problem.

>I can store them with Activity Name as key but there might be issues if the process diagram contains Cycles which are executing in parallel.
If you have data to process divided by some chunks, you can update/process each chunk separately. In general case it doesn't matter if execution X does some part of work on it and then execution Y does next part of work. If you agressively use parallel executions you might need separate out-of-activiti-transaction store for your data as transactions limit capabilities of process executions to one thread per process modifying its process scope variables.

>I also could not understand execution.getParentId() behavior.
In general case parent id is top execution of the process, that is first execution created to start process. I think embeded subprocess creates child execution, but I'm not sure as I try to stay away from parallel non-exclusive executions for processes due to limitations on process variables modifications.