broun
broun

Reputation: 2593

Race condition with Spring managed beans in webservice

Consider a spring manged web service which defines an operation opA (class opA). A separate instance of the opA object will be created for every request for that operation.

Class opA{

@Autowired
B objB;

}

Class B{

C objC;
.
.
}

Class C{
.
.
.
}

<bean id="objB" class="blah.blah.B">
 <property name="objC">
   <bean class="blah.blah.C"/>
  </property>
</bean> 

NOTE: opA is also managed by spring

Here the object objB is Spring singleton scope with an inner bean objC. Now if two requests for opA arrive at the same time they both will have the same instance of objB right? causing a possible race condition on the sate of objC in objB. Am i correct? If not can you please explain why?

Upvotes: 1

Views: 844

Answers (1)

Andrea Vacondio
Andrea Vacondio

Reputation: 954

You have a single instance with state that's used all around your application so I'd say that you may have race conditions, but it depends on what is your state (is objB a Service and objC a Repository?) and on your implementation.

Upvotes: 1

Related Questions