Announcement Announcement Module
No announcement yet.
Need clarification on POJO instance(s) creation under SI domain.. Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Need clarification on POJO instance(s) creation under SI domain..


    I would like to understand on how my POJO instance(s) are being handled under SI f/w by the container.

    Below are the details:

    I've a POJO defined as below:

    public class MyReqMsgBuilder {
    private RptExecutionSvcRequest executionServiceReq;
    public Message<RptExecutionSvcRequest> getRptExecutionSvcReqForDataEngine(Message<?> message) {
    //some more code logic goes here and finally return the executionServiceReq VO as a payload to an SI message
    The POJO is defined as a bean under spring config file

    <bean id="executionSvcReqMsgBuilder" class="">
    And this POJO gets invoked by a <service-activator> under a chain:

     <int:chain input-channel="ersSvc2execSvcQMRChannel" output-channel="executionSvcSubmitAdhocReqChannel">
                <int:transformer ref="json2ObjTransformer" method="transformToERSOrchestrationSvcReq" />
                <int:service-activator ref="executionSvcReqMsgBuilder" method="getRptExecutionSvcReqForDataEngine" />
                <int:transformer ref="obj2JsonTransformer" method="transformFromRptExecutionSvcReqForDataEngine" />
                <int:service-activator ref="msgReqAuditDAOIntegrator" method="persist" />
                <int:service-activator ref="msgReqAuditDetailDAOIntegrator" method="persist" />
    Based on above configuration details, I would like to know, in case of a multi-threaded environment (i.e., say more than one threads are simultaneously invoking the above <chain> element)

    1) How many instances of my POJO class is created ? Does each thread get its own instance of POJO (i.e., does <service-activator> create a new instance of my POJO for each caller thread) ?
    2) Assuming that only one POJO instance is created across multiple threads (i.e., is singleton),will the auto-wired placeholders (i.e., the auto-wired instance variables) will also be singleton ?
    3) Assuming everything is singleton (the POJO, the auto-wired instance variables, etc), will it not be an issue when the auto-wired variable (i.e., executionServiceReq) tries to call "setter" methods ? Will the resultant RptExecutionSvcRequest value object not have a mix of setter values recvd from different threads (in other words,
    executionServiceReq.setMessageHeader(header) might be called for one thread while executionServiceReq.setMessageBody(executionServic eReqMsgBody) might be called from other thread) ?

    Thanks to clarify (Gary - would be great if you too provide your feedback on this).

    Pls let me know if any further info is needed to elaborate my queries.

    Best Regards

  • #2
    1. 1
    2. Yes
    3. Yes

    Your services must be thread safe (no unprotected shared state [instance variables]).


    • #3
      If I define my bean with "prototype" scope, will that make it thread-safe ?



      • #4
        No, that just means each reference to the bean gets a new instance, but you only have one reference so it will make no difference.