What does “Container” mean in the context of programming?

孤者浪人 提交于 2019-11-30 12:08:54

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.

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.

A Web application runs within a Web container of a Web server.The Web container 
provides the runtime environment through components that provide naming context 
and life cycle management. 

Ex. Container in case of java is the runtime environment and the implementation of API give by java .
Like
1. Servlet container is responsible for managing the lifecycle of servlets..

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!