Definition of a Java Container

2019-01-16 11:24发布

I've read\heard many times about java containers such as a servlet container, however, I can't seem to find a good definition of what a container is in the enterprise java world.

Does anyone know of a good definition of an enterprise java container?

8条回答
Luminary・发光体
2楼-- · 2019-01-16 11:56

Referring more generally to the Container pattern (of which an enterprise Java container could be considered a specialization), the book Server Component Patterns by M.Volter, et al. offers the following:

[A CONTAINER provides] an execution environment that is responsible for adding the technical concerns to the COMPONENTS...Conceptually, it wraps the COMPONENTS, thus giving clients the illusion of of tightly-integrated functional and technical concerns.

Examples of such technical concerns include security, transaction management, logging, etc.

查看更多
男人必须洒脱
3楼-- · 2019-01-16 12:02

The common containers in Java EE are servlet container and the EJB container, and I see these as examples of IoC(Inversion of Control) containers. The crucial aspects are :

  1. Your code does not have any main() or "wait here for a request logic" - the container starts up and configures itself and then eventually initialises your code and delivers requests
  2. Your code may be one of many similar classes (servlets in a servlet container, EJBs in an EJB container) whose instances have life-cycles to be controlled by the container.
  3. Requests are delivered to your servlet or EJB via some protocol defined by the container, using resources (eg. HTTP ports) controlled by the container, and possibly with considerable infrastructure cleverness (look at the HTTP request queues, EJB load balancing etc.)
  4. There's considerable added value from functions such as transaction control and security management - as the container is calling your code it is well-placed to implement this unintrusively.
  5. The main container functionality is very much IOC, the container calls your code at appropriate times, however the container will also provide useful APIs that your code can call (eg. to get Servlet or EJB Contexts.
查看更多
登录 后发表回答