12

I am learning Spring and the term "Spring Container" frequently shows up in the text. However, I know "container" is not used only in Spring (EJB container etc) so what does it mean when used in the context of programming?

skaffman
  • 398,947
  • 96
  • 818
  • 769
LuckyLuke
  • 47,771
  • 85
  • 270
  • 434

2 Answers2

17

The container is something that contains something else.

  • In : Spring container contains beans (Java objects that are subject to )

  • Servlet containers contain servlets, filters, listeners, etc. and manages their state and lifecycle. There are also similar containers

  • EJB containers contain EJBs (stateless, stateful, message-driven) and, as above, manage their pooling and lifecycle

  • java.awt.Container "is a component that can contain other AWT components"

As you can see the role of the container is to own and manage a set of objects so you don't have to instantiate them directly.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • 3
    I think that your answer would be acceptable if you left only the 1st sentence. ;) – aviad Mar 16 '12 at 09:05
  • 1
    No it wouldn't. I'm with the OP, the term container is such a loaded term in software and if it's so generic it shouldn't be used. Atoms are containers according to the first sentence. They contain protons and electrons but who cares? And who cares that a 2D box in a diagram contains empty space? There must be more to it. What do we do with the contents? Why do we want to put them inside a container? e.g. "contain something that you might need global access to in your code base to invoke dependent logic"? – Sridhar Sarnobat Nov 18 '15 at 00:35
  • 1
    This is key: "to own and manage a set of objects so you don't have to instantiate them directly." – Sridhar Sarnobat Nov 18 '15 at 00:41
1

What you're asking is a bit obscure to me. I guess you are asking what "containers" do in general.

My comprehension is that container is a pool managing a series of objects/beans. For example there is the web container TOMCAT, the general IoC container in Spring, or even the thread-pool has also similarities. Container deals with mostly all the business of what it contains, like the life-cycle, the dependency between each object. And what we need to do is just to generate an object and put it to container, and get it when in need.

Wish that will help.

Southeast
  • 587
  • 2
  • 5
  • 11