I would like your help about whether there is a known way to add dynamically a task to a process instance after the deployment using java code. Specifically, I start by reading the XML file then I deploy the process and afterwards I want to add for instance a user task. Is this possible? Any help and suggestions would be appreciated!
2) Dynamically add a subtask to a process instance.
3) Dynamically choose a sub-process.
4) Dynamically set the implementation of a service task or other expression.
5) Programmatically changing the running version of the process definition (note this will apply for all process instances using the version when you make that change).
6) Adding additional conditional logic in a listener.
I think there are more. Not all of them will necessarily address your particular use-case.
There are limitations. If you need to make a change that depends upon a java class that hasn't been deployed yet then you'll get an error at execution time when you hit that task. You can try to do clever things with the java classloader to avoid a restart but that's tricky ground.
The difficulty might be less whether there is a way and more understanding all of the techniques that are available and fitting them to your case. Personally I would tend to try and go for something that retains as much of a connection to the original process diagram as possible in order to retain visibility of what it is that is running (which in your case sounds to me like 1). But there may be circumstances where that isn't adequate and yours might be such a circumstance as I don't know how much flexibility you need. It would be good if you can share as much as possible as it is a tricky area and your experiences could help the community.
So, from your suggestions the one that matches my aims is number 4(Dynamically set the implementation of a service task or other expression). If I understood correctly from the other threads in case that I have:
and after the deployment my currently state is at userTask1 and waiting. The only way to add dynamically a userTask2.5 ( UserTask2 –> UserTask2.5 --> UserTask3 –>) is to redefine the BpmnModel creating it from the beginning (copying the existed one and adding the userTask2.5) and redeploy using the new BpmnModel?
I'm a bit confused that you say UserTask here as a task with a custom java implementation in Activiti is normally called a Service Task. See Activities | Alfresco Documentation for the terminology. It sounds like what you are trying to do is to deploy a new version of the process and migrate the instances to the new version. For the options on that see