cancel
Showing results for 
Search instead for 
Did you mean: 

ServiceTask creating lots of new beans

halfsoft
Champ in-the-making
Champ in-the-making
I am calling a lot of expressions in ServiceTasks and also checking for conditions in the flow, the bean is declared in the following way:

<bean id="core" class="org.springframework.jndi.JndiObjectFactoryBean">
        <property name="jndiName" value="java:global/platform-core/platform-core-ejb/Core"/>
        <property name="cache" value="true"/>
    </bean>
</beans>

<!–break–>
However in the stateless bean I have a printLn(String) in the @PostConstruct annotated method and it gets called after every expression evaluation, which makes me believe it creates a new stateless bean instance for each call. How can I make activiti cache the bean and reuse it? Or at least make sure that it uses an object pool?
2 REPLIES 2

vasile_dirla
Star Contributor
Star Contributor
did you try to set explicitly scope="singleton" for your JndiObjectFactoryBean ?
the cache = true is the default behaviour of the JndiObjectFactoryBean and if you are sure cache is on and this FactoryBean is singleton then it should work,

if not, just turn on the debugger and check the instances when fetching the bean.

halfsoft
Champ in-the-making
Champ in-the-making
If the bean is Singleton then having 100 different process instances call the same methods is a not a good idea(most of them will time out while waiting for somebody else to finish his call of the method).
It is the same with the Statefull, if I set the JndiObjectFactoryBean to cache the object - i get the same object, but this leads to the same exception. If statefull and cache off It will throw "method not found" exceptions (something with the proxy gets broken).

If stateless - works, but every call to the bean is creating a new object and injecting everything necessary in it, which is slow.

So:
1. Using JndiObjectFactoryBean:
Singleton - cache on - only one global object, timeout exception when several threads try to call the same method
Singleton - cache of - only one global object, timeout exception when several threads try to call the same method
Statefull - cache on - only one global object, timeout exception when several threads try to call the same method
Statefull - cache off - many objects, method not found exception
Stateless - cache on - huge amount of objects get created, works
Stateless - cache off - not tested, but i think the result will be like "Stageful no cache"

2. Using the class name directly (<bean id="core" class="com.packageName.Core">
The object does not get created as a bean at all, so nothing gets injected(i need to manually find the references to the helper beans by using JNDI), also only one object is created and reused so no pooling at all.


What is the recommended way to call methods in EJB's when there is also high concurrency?