Variables are cached in the Request or Conversation until the unit of work is ended, for example by calling completeTask()
. There is currently no out-of-the-box solution for manually flushing the cached variables. You could work around this by writing a Cdi Bean which injects the ContextAssociationManager and performs the flush:
@Inject
private ContextAssociationManager contextAssociationManager;
@Inject
private TaskService taskService;
public void flushCachedVariables() {
String taskId = contextAssociationManager.getTask().getId();
taskService.setVariables(taskId, contextAssociationManager.getCachedVariables());
}
The difference between signalExecution
and completeTask
is as follows:
completeTask
: will complete the currently associated task using the TaskServicesignalExecution
: is more abstract: it sends a signal to the currently associated execution to continue execution. In this case the effect is the same: the task is completed and execution continue. ButsignalExecution
will also work in situations where there is no Human Task involved (ie. a ReceiveTask).