Class ProcessEngineContext
When a Process Engine API call is performed, the engine will create a Process Engine Context. The context caches database entities, so that multiple operations on the same entity do not result in multiple database queries. This also means that the changes to these entities are accumulated and are flushed to the database as soon as the Process Engine API call returns (however, the current transaction might be committed at a later time).
If a Process Engine API call is nested into another call, the default behaviour is to reuse the existing Process Engine Context. This means that the nested call will have access to the same cached entities and the changes made to them.
When the nested call is to be executed in a new transaction, a new Process Engine Context needs to be created for its execution. In this case, the nested call will use a new cache for the database entities, independent of the previous (outer) call cache. This means that, the changes in the cache of one call are invisible to the other call and vice versa. When the nested call returns, the changes are flushed to the database independently of the Process Engine Context of the outer call.
The ProcessEngineContext is a utility class to declare to
 the Process Engine that a new Process Engine Context needs to be created
 in order for the database operations in a nested Process Engine API call
 to be separated in a new transaction.
  try {
    ProcessEngineContext.requiresNew();
    runtimeService.startProcessInstanceByKey("EXAMPLE_INSTANCE");
  } finally {
    ProcessEngineContext.clear();
  }
 - 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionstatic voidclear()Declares to the Process Engine that the new Context created by therequiresNew()method can be closed.static voidDeclares to the Process Engine that a new, separate context, bound to the current thread, needs to be created for all subsequent Process Engine database operations.static <T> TwithNewProcessEngineContext(Callable<T> callable) Takes a callable and executes all engine API invocations within that callable in a new Process Engine Context.
- 
Constructor Details- 
ProcessEngineContextpublic ProcessEngineContext()
 
- 
- 
Method Details- 
requiresNewpublic static void requiresNew()Declares to the Process Engine that a new, separate context, bound to the current thread, needs to be created for all subsequent Process Engine database operations. The method should always be used in a try-finally block to ensure thatclear()is called under any circumstances. Please see theProcessEngineContextclass documentation for a more detailed description on the purpose of this method.
- 
clearpublic static void clear()Declares to the Process Engine that the new Context created by therequiresNew()method can be closed. Please see theProcessEngineContextclass documentation for a more detailed description on the purpose of this method.
- 
withNewProcessEngineContextTakes a callable and executes all engine API invocations within that callable in a new Process Engine Context. Please see the An alternative to calling:ProcessEngineContextclass documentation for a more detailed description on the purpose of this method.try { requiresNew(); callable.call(); } finally { clear(); }- Parameters:
- callable- the callable to execute
- Returns:
- what is defined by the callable passed to the method
- Throws:
- Exception
 
 
-