1
votes

I am working with preparing a solution for one of my uscases. My solution is something that might look like this in abstract.

My question here is, when the two main flows are calling the same sub-flow cuncurrently, it is going to work without any issues ?

Also do I need to write the code as thread safe for all the classes that are being used as custom components/trnasformers in the sub-flow ?

My abstract configuration looks as given below.

<flow name="mainflow_1" >
    <inbound-endpoint/>
    <transformer ....>
    <component ....>
        <flow-ref name="subflow_1"></flow-ref>
    <transformer ....>
    <component  ...>
    <outbound-endpoint ....>
</flow>

<flow name="mainflow_2" >
    <inbound-endpoint  type="request-response" />
    <transformer ....>
    <component ....>
        <flow-ref name="subflow_1"></flow-ref>
    <transformer ....>
    <component  ...>            
</flow>

<sub-flow name="subflow_1" >        
    <transformer ....>
    <component ....>
        <outbound-endpoint  call to some service >
    <transformer ....>
    <component  ...>        
</sub-flow>

Please guide me.

1

1 Answers

5
votes

A sub-flow acts like a macro: execution wise, it's as if the elements of the sub-flow were copied in the calling flow.

Thus it's the threading behaviour of the calling flow that will determine the threading behaviour of the sub-flow.

Whether they're used in sub-flows or main flows, you should write your component classes to be thread safe if you use singleton instances of them (the common use case). If you use prototype instances (one instance created per request) or pooled instances (limited number of instances, bottlenecks the threads), your component classes can be thread unsafe.

As a rule of thumb, strive for thread-safe stateless component classes as much as you can to save you potential optimization pain down the road.