Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Core Container dependency Injection Behaviour?

 
scott miles
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As core container inject the dependency with bean id defined in spring-config.xml. My question can configure the objects here which are
holding some state? I mean two request comes for the same object at same time , will container create the new instances for both of them
if the scope is prototype? Last question is does container maintain some pool for the created objects or they are good for garbage collection
as soon as they are finished?
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you set the scope to "prototype" everytime someone calls getBean() will get a new instance. However, typically, most beans are objects that do not hold state and having a single instance only is plenty to support many clients all at the same time. There would be no thread issues. Spring does not pool objects, there is no need for pools of Spring beans.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic