-
1. Re: Java instance being reused across workflows.
ajaygautam Dec 21, 2009 11:16 AM (in response to ajaygautam)Might be worth mentioning that I tried to reproduce the error with JBPM examples, but was UNABLE to do so...
Complete updated files attached (if you want to resun the test and see that it works fine for examples). Here are my changes:package org.jbpm.examples.java
// ...
public class JavaInstantiateTest extends JbpmTestCase {
// ...
public void testJavaInstantiateFine() {
final Map<String, Object> variables = new HashMap<String, Object>();
variables.put("hand", new Hand());
variables.put("joesmoe", new JoeSmoe());
variables.put("newState", "fine");
final ProcessInstance processInstance = executionService.startProcessInstanceByKey("Java", variables);
final String pid = processInstance.getId();
final String answer = (String) executionService.getVariable(pid, "answer");
assertEquals("I'm fine, thank you.", answer);
final Hand hand = (Hand) executionService.getVariable(pid, "hand");
assertTrue(hand.isShaken());
}
public void testJavaInstantiateSmooth() {
final Map<String, Object> variables = new HashMap<String, Object>();
variables.put("hand", new Hand());
variables.put("joesmoe", new JoeSmoe());
variables.put("newState", "Smooth");
final ProcessInstance processInstance = executionService.startProcessInstanceByKey("Java", variables);
final String pid = processInstance.getId();
final String answer = (String) executionService.getVariable(pid, "answer");
assertEquals("I'm Smooth, thank you.", answer);
final Hand hand = (Hand) executionService.getVariable(pid, "hand");
assertTrue(hand.isShaken());
}
}Update to jbpm java task:
<java name="greet"
class="org.jbpm.examples.java.JohnDoe"
method="hello"
var="answer"
g="96,16,83,52">
<field name="state"><object expr="#{newState}"/></field>
<arg><string value="Hi, how are you?"/></arg>
<transition to="shake hand" />
</java>This works as it should!
So... I think I am doing a stupid mistake somewhere, but can't really put my finger on it.
Any help / pointers in the right direction would be appreciated.
Thanks
Ajay Gautam
-
process.jpdl.xml 822 bytes
-
JohnDoe.java.zip 944 bytes
-
JavaInstantiateTest.java.zip 1.2 KB
-
-
2. Re: Java instance being reused across workflows.
ajaygautam Dec 21, 2009 2:11 PM (in response to ajaygautam)Changing the debug level from DEBUG to TRACE reveals that the code tries to create a ReporitoryCache.
2009-12-21 13:49:19,743 DEBUG Log4jLog - executing activity(Check Amendment Type)
2009-12-21 13:49:19,743 TRACE Log4jLog - org.jbpm.pvm.internal.repository.RepositoryCache not found in transaction 26358318
2009-12-21 13:49:19,743 TRACE Log4jLog - found org.jbpm.pvm.internal.repository.RepositoryCache in process-engine
2009-12-21 13:49:19,743 TRACE Log4jLog - delivering org.jbpm.pvm.internal.repository.RepositoryCacheImpl
2009-12-21 13:49:19,759 DEBUG CheckTradeAttribute - Constructing CheckTradeAttribute. I am com.rbs.gbm.rates.workflowengine.engine.CheckTradeAttribute@14af469
......
2009-12-21 13:49:20,165 DEBUG Log4jLog - executing activity(Check Amendment Type)
2009-12-21 13:49:20,165 TRACE Log4jLog - creating null
2009-12-21 13:49:20,165 TRACE Log4jLog - searching for method compareTradeAttribute in com.rbs.gbm.rates.workflowengine.engine.CheckTradeAttribute
2009-12-21 13:49:20,165 TRACE Log4jLog - found matching method com.rbs.gbm.rates.workflowengine.engine.CheckTradeAttribute.compareTradeAttributeFor the first unit test, the cache is created, and populated with a new object. For the 2nd unit test, the same object is retrieved from the cache!
Any way to change the behavior to create new object every time?
Ajay
-
3. Re: Java instance being reused across workflows.
kukeltje Dec 22, 2009 2:09 AM (in response to ajaygautam)Afaik, you need to assume statelessness in the automatic java activities, just like with stateless sessionbeans. The difference between your example and the testcase is the visability of the member field (private vs package ('default')). Try changing that
Cheers,
Ronald
-
4. Re: Java instance being reused across workflows.
ajaygautam Dec 27, 2009 10:29 AM (in response to kukeltje)What I found is that if I have members in the object, its cached, but if I remove all members, and pass all data using parameters, then the instance is not cached. I converted the calls to params, and its working fine now. -
5. Re: Java instance being reused across workflows.
jbarrez Dec 28, 2009 7:09 AM (in response to ajaygautam)As Ronald states, automatic activitites should't have state. So if you want to inject runtime data, you'll have to pass them by parameter.
This is also described in the user guide:
-
6. Re: Java instance being reused across workflows.
ajaygautam Dec 28, 2009 7:38 AM (in response to jbarrez)Thanks for pointing that out Joram.
Must have overlooked it.
Happy new year.