If you’re using injection, then I recommend sticking to CDI and avoid mixing in EJBs. The difference is subtle… but noticeable (meaning you’ll see errors) when you begin using advanced features such as cdi’s applicationscoped vs ejb’s singleton (see google: cdi applicationscoped vs singleton… discussions).
Leaning towards CDI, also avoid using injection requiring EJB and then later mixing formal (i.e. java-bean management) requirements. Difference is subtle - but, it’s reasonably easy to search/replace various annotations to later clean-up the overlap.
Here’s how I do it:
I frequently pass in the “execution” parameter when calling on task delegates by using the expression value:
#{stpProcessDemo.camundaSaysHello(execution)}
And, within these delegates I typically make available Camunda’s runtimeService:
@Inject
private RuntimeService runtimeService;
Based on general requirements, most of the beans are “RequestScoped”.
Here’s a trivial example of setting a process-instance delegate:
public void camundaSaysHello(DelegateExecution execution) {
LOGGER.info("*** camundaSaysHello: invoked");
execution.setVariable("camundaGreeting", "Hello from Camunda");
}
I switch to “applicationScope” for singletons. But, I usually reference these singletons from within the java delegate as a property. This means you won’t see an “applicationScoped” session set at the top of my java-BPM delegates. I use singletons for things like centrally managed property values, timers, and sharing outbound communication (i.e. ReST) connections.
On occasions where Camunda is running as a batch-processing engine, and performance is absolutely critical, then you’ll begin figuring in “applicationScoped” delegates. But, typically BPM-batch processing implies performance allowances. This necessary to build-in all the BPM-engine goodness/features.
This requires some research - but, from memory, I think I fell back on using “static” - though being VERY MINDFUL of how these statics behave within async and server cluster configurations. Usually using “static” for utility oriented requirements such as “value conversion” (etc.).
But, most of the time, and trying to avoid later headaches… I use the default “sessionScope” delegate CDI beans. And, if there’s a need to reference “applicationScope”, it’s done via a property within a seessionScope delegate.