Java Types Of Sessions

Posted on

Sessions in Postman is a newly introduced feature (after version 6.2) which was much needed before this was introduced.It has solved a problem of sharing sensitive information you used in the project with other members of the team which may or may not be located with you.

  1. Session In Java Servlet

Types of Session Beans

Session beans are of three types: stateful, stateless, and singleton.

Stateful Session Beans

The stateof an object consists of the values of its instance variables. In a statefulsession bean, the instance variables represent the state of aunique client/bean session. Because the client interacts (“talks”)with its bean, this state is often called the conversational state.

As its name suggests, a session bean is similar to an interactive session.A session bean is not shared; it can have only one client, in the same waythat an interactive session can have only one user. When the client terminates,its session bean appears to terminate and is no longer associated with theclient.

Session In Java Servlet

The state is retained for the duration of the client/bean session. Ifthe client removes the bean, the session ends and the state disappears. Thistransient nature of the state is not a problem, however, because when theconversation between the client and the bean ends, there is no need to retainthe state.

Stateless Session Beans

Different types of sessions

A stateless session bean does not maintain aconversational state with the client. When a client invokes the methods ofa stateless bean, the bean’s instance variables may contain a statespecific to that client but only for the duration of the invocation. Whenthe method is finished, the client-specific state should not be retained.Clients may, however, change the state of instance variables in pooled statelessbeans, and this state is held over to the next invocation of the pooled statelessbean. Except during method invocation, all instances of a stateless bean areequivalent, allowing the EJB container to assign an instance to any client.That is, the state of a stateless session bean should apply across all clients.

Because they can support multiple clients, stateless session beans canoffer better scalability for applications that require large numbers of clients.Typically, an application requires fewer stateless session beans than statefulsession beans to support the same number of clients.

Java Types Of Sessions

A stateless session bean can implement a web service, but a statefulsession bean cannot.

Singleton Session Beans

A singleton session bean is instantiated onceper application and exists for the lifecycle of the application. Singletonsession beans are designed for circumstances in which a single enterprisebean instance is shared across and concurrently accessed by clients.

Singleton session beans offer similar functionality to stateless sessionbeans but differ from them in that there is only one singleton session beanper application, as opposed to a pool of stateless session beans, any of whichmay respond to a client request. Like stateless session beans, singleton sessionbeans can implement web service endpoints.

Singleton session beans maintain their state between client invocationsbut are not required to maintain their state across server crashes or shutdowns.

Types

Applications that use a singleton session bean may specify that thesingleton should be instantiated upon application startup, which allows thesingleton to perform initialization tasks for the application. The singletonmay perform cleanup tasks on application shutdown as well, because the singletonwill operate throughout the lifecycle of the application.