Suspending a process instance unconditionally

It can certainly be used directly as java - i was just expressing the most common use-case in which a source (external to the process instance itself) is responsible for suspending or activating an instance. It’s not always the case that an instance suspends itself, because it then becomes more complicated to re-activate itself because a process instance being suspended means that no jobs or tasks will be completed for that instance and so it cannot decided to activate itself.

Hope that clarifies why i was questioning the use case you have.

So the answer to my question is essentiall “no”? The process instance can’t suspend itself no matter what?

It can, but it cant reactivate itself.

1 Like

It can

How?

I’ll see if i can create an example for you.

1 Like

Much appreciated! You need not make it too complicated, i’m able to read javadocs and decompiled code ;), just point me at the right direction.

Here’s an example i created using spring boot

2 Likes

Ah, so i must use RuntimeService#updateProcessInstanceSuspensionState instead? Lemme check if it helps.

There’s a little more to it - you also have to take into account where the transaction boundaries are.

Hmm, using updateProcessInstanceSuspensionState doesn’t work as well.

where the transaction boundaries are

Do you mean that the engine will complete transaction regardless of the suspension state?

suspension means that further jobs will will not be picked up by the engine so once the suspension commits to the DB any further jobs will not be picked up. which is why i added asynchronous before on the script tasks to ensure that after a suspension it would not continue the process.

In my case i use synchronous java delegate service tasks in a simple workflow of two such consecutive tasks. Even that i invoke updateProcessInstanceSuspensionState in the first task, the second still executes.

So adding a transaction boundary before the second service task should suspend the instance then. If your whole process in entirely synchronous then suspension will not work.

2 Likes

Ah, i see now. Why is that? Is there some docs i can read about this behaviour? In other words, if i don’t use anything in terms of transaction management (for my tests), - i won’t be able to do what i want?

You can check out this section of the docs for more detailed information.

No, i mean, something about why i can’t suspend a synchronous process? i can’t see any logical reason for that :).

It’s just because the engine never wanted to stop a thread in-flight, it would cause havoc. instead if you want to. it will only suspend an instance if it’s found a safe wait sate.

suspending a synchronous process would mean that he engine would have to create a state between what the user has defined as a transaction (i.e. the number of task executed between 2 transaction boundaries). Transaction boundaries are defined in design time and not runtime.

Hence asynch continuations exist, i see now. Thanks alot, Niall, i will come back later when i’ve better understood what we just discussed :).

Great, much appreciate your help, Niall! I managed to do what i needed with enabling <property name="jobExecutorActivate" value="true" /> and declaring camunda:asyncBefore="true" on tasks.

I have another question however, about executing those tasks after reactivating the process instance, i will create a new thread for it.

1 Like