43

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?

skaffman
  • 381,978
  • 94
  • 789
  • 754
javamonkey79
  • 16,837
  • 35
  • 104
  • 166

8 Answers8

43

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.
djna
  • 52,574
  • 11
  • 70
  • 109
22

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.

Brandon E Taylor
  • 23,667
  • 6
  • 43
  • 68
7

Java EE Containers

Normally, thin-client multitiered applications are hard to write because they involve many lines of intricate code to handle transaction and state management, multithreading, resource pooling, and other complex low-level details. The component-based and platform-independent Java EE architecture makes Java EE applications easy to write because business logic is organized into reusable components. In addition, the Java EE server provides underlying services in the form of a container for every component type. Because you do not have to develop these services yourself, you are free to concentrate on solving the business problem at hand.

http://download.oracle.com/javaee/5/tutorial/doc/bnabo.html

biegleux
  • 12,934
  • 11
  • 42
  • 52
Marek Sebera
  • 37,155
  • 34
  • 153
  • 231
5

The key notion behind a container is inversion of control, where application components inside the container can be loosely coupled with other application components as well as lower-level resources they depend upon. For Java these resources are usually things like database connections, network connections, JNDI, etc.

Different tiers of containers support different specifications for instance a web/servlet container like tomcat does not support some application level specifications like EJB3, therefore tomcat cannot wire together ejb's for injection into your application.

jpredham
  • 2,059
  • 1
  • 22
  • 36
  • 2
    Is a container always IoC? For instance, the servlet container. – javamonkey79 Aug 22 '11 at 18:29
  • 1
    Any modern servlet container definitely uses paradigms of IoC. While there is no formal specification it's commonly accepted that this is the best way we know how to solve that problem. – jpredham Aug 22 '11 at 18:40
2

"Containers are the interface between a component and the low-level platform-specific functionality that supports the component. Before a web component, enterprise bean, or application client component can be executed, it must be assembled into a Java EE module and deployed into its container." here is my source : http://docs.oracle.com/javaee/1.4/tutorial/doc/Overview3.html

Arjan Tijms
  • 36,666
  • 12
  • 105
  • 134
grepit
  • 16,512
  • 5
  • 83
  • 71
2

A container is execution environment that brings dynamism. It creates HTTP response, converts HTTP request to an object and creates and manages servlet life cycle.

Java EE is the collection of the specification that are used to solve enterprise problems like security, scalability, robustness, availability etc.

A container that manages every specification of Java EE is known as Java enterprise container. Eg. glassfish, JBoss etc. (BTW Tomcat is not EE container it is web container)

Abinash
  • 33
  • 8
1

It is responsible for maintaining the individual components on the server side, which include Java servlets, Java server pages and Java server faces.

ben H
  • 11
  • 1
-1

Container- in the context of Java development, refers to a part of the server that is responsible for managing the lifecycle of Web applications. The Web applications specify the required lifecycle management with the help of a contract presented in XML format. The Web container cannot be accessed directly by a client. Rather, the server manages the Web container, which in turn manages the Web application code.

Ref- https://www.techopedia.com/definition/4252/container-java

sudar
  • 1,305
  • 1
  • 11
  • 24