EJB

EJB Projects

EJB Project 1

EJB Examples

EJB EXAMPLE

adplus-dvertising
What is a Session Beans?
Previous Home Next

Session beans are distributed components which encapsulate business logic and an application. A Session beans represents a single client inside the J2EE server.

The session is access an application that is deployed on the server, and the client invokes the session bean's methods. The session bean performs work for its client, and shielding the client from complexity by executing business tasks inside the server.

As its name suggests, a session bean is similar to an interactive session. A session bean is not shared, it may have just one client, in the same way that an interactive session may have just one user. Like an interactive session, a session bean is not persistent. (That is, its data is not saved to a database.) When the client terminates, its session bean appears to terminate and is no longer associated with the client.

Session bean can be two types
  1. Stateless: In Stateless Session beans intermediate state is not maintain. A stateless session bean does not maintain a conversational state for a particular client. When a client invokes the method of a stateless bean, the bean's instance variables may contain a state, but only for the duration of the invocation. When the method is finished, the state is no longer retained. Except during method invocation, all instances of a stateless bean are equivalent, allowing the EJB container to assign an instance to any client.
  2. Because stateless session beans can support multiple clients, they can offer better scalability for applications that require large numbers of clients. Typically, an application requires fewer stateless session beans than statefull session beans to support the same number of clients.

    At times, the EJB container may write a statefull session bean to secondary storage. However, stateless session beans are never written to secondary storage. Therefore, stateless beans may offer better performance than statefull beans.

    Examples: Premium alculation of insurance intermediate state is maintain.

  3. Statefull Beans: How A client invokes an EJB.shtmlIn Statefull Session beans intermediate state is maintain. The state of an object consists of the values of its instance variables. In a statefull session bean, the instance variables represented to state of a unique client-bean session. Because the client interacts (talks) with its bean, this state is often called the conversational state.

    The state is retained for the duration of the client-bean session. If the client removes the bean or terminates, the session ends and the state disappears. This transient nature of the state is not a problem, however, because when the conversation between the client and the bean ends there is no need to retain the state.

  4. Example: shopping card.

When to using and utilizing Session Beans:

In general, you should use a session bean if the following circumstances hold:

  • In the Session beans using to client into one client has access to the bean instance for the given time .
  • The state of the bean is not persistent, it's existing only for a short period of time (perhaps a few hours).

Stateful session beans are appropriate if any of the following conditions are true:

  • The Session bean's state representing the interaction between the bean and a specific client.
  • The Session bean's needs to hold the information about the client across method invocations.
  • The Session bean's immediate between the client and the other components of the application, presenting a simplified view to the client.
  • Behind the scenes, the bean managed to all the work flow of several enterprise beans.

To improve performance, you might choose a stateless session bean if it has any of these traits:

  • The bean's state has no data for a specific client.
  • The session bean's a single method invocation, the bean's performs a generic task for all clients.
  • Example, you might use a stateless session bean to send an e-mail that confirms an online order.
  • The bean fetches from a database a set of read-only data that is often used by clients. Such a bean, Example, could retrieve the table rows that represent the products that are on sale this month.
Previous Home Next