JbpmContext usage & best practices
srlucas Jan 14, 2009 9:44 AMHi!,
I am using JBPM + Spring (springmodules0.8a) + Struts to create an application.
I would like to know what are the best practices regarding the jbpmContext and how to create it/reuse it.
This is my spring configuration
<bean id="dc-workflow" class="org.springmodules.workflow.jbpm31.definition.ProcessDefinitionFactoryBean"> <property name="definitionLocation" value="classpath:dc/processdefinition.xml"/> </bean> <bean id="jbpmConfiguration" class="com.ea.dc.core.CustomLocalJbpmConfigFactoryBean"> <property name="sessionFactory" ref="sessionFactory"/> <property name="configuration" value="classpath:jbpm.cfg.xml"/> <!-- property name="configuration" value="classpath:jbpm.cfg.xml"/ --> <property name="processDefinitions"> <list> <ref local="dc-workflow"/> </list> </property> <property name="processDefinitionsResources"> <list> <value>classpath:dc/processdefinition.xml</value> </list> </property> </bean> <!-- jBPM template --> <bean id="jbpmTemplate" class="org.springmodules.workflow.jbpm31.JbpmTemplate"> <constructor-arg index="0" ref="jbpmConfiguration"/> <constructor-arg index="1" ref="dc-workflow"/> </bean>
and then I am injecting those beans to a service of mine...
now, whenever I want to do something with the workflow, I do something like:
/** Moves the process forward. * * @param jobId the process instance id * @param transitionId the transition id to select */ public void moveForward(final Long jobId, final String transitionName){ JbpmContext jbpmContext = getContext(); try { ProcessInstance instance = jbpmContext.getProcessInstanceForUpdate(jobId); instance.signal(transitionName); } finally { // make sure we save everything jbpmContext.close(); } }
as shown in the documentation...
the thing is... I am closing the context every time I leave a service method...
isn't it better to leave it open? Is this a good practice?
I was thinking about using something similar to openSessionInView for the jbpmContext (though I'm not sure how to do it)... will that be better?
Any ideas/pointers would be great!
Thanks a lot,
Lucas