2

I'm running through again the Javaee7 oracle documentation and here's what's stated.

"A singleton session bean is instantiated once per application and exists for the lifecycle of the application. Singleton session beans are designed for circumstances in which a single enterprise bean instance is shared across and concurrently accessed by clients."

I do understand perfectly what it is saying. However come to think of it, the word session is very misleading here. Since it exists at application level, the term 'session' doesn't seem to apply here.

When i think of the word 'session', i think in terms of each individual user as a session. If that singleton session bean is for across application, shouldn't it not be called a session bean (instead probably a application bean would be better understood).

Any opinion?

yapkm01
  • 3,590
  • 7
  • 37
  • 62

2 Answers2

0

When i think of the word 'session', i think in terms of each individual user as a session

The term "session" in this context means unit of work or business transaction.

In Stateless and Singleton beans, a new session/business transaction is opens when a new request arrives, and it lives until the response it sent back to the client. (session-per-request pattern)

For Stateful Session bean the business transaction could implies several client requests. From the Stateful bean's perspective, a client is a proxy that sends the requests to the same stateful instance.

Edit (too long for comment)

I think Application Bean could probably be a good name, in fact they are good for storing application settings, but the key point is why they are called Session Bean.

In this context "session" is the period of time the business transaction executes. For Stateless and Singleton this period matches with the request/response cycle.

...If that singleton session bean is for across application, shouldn't it not be called a session bean

The fact that a Singleton maintains its state between client invocations doesn't means that the session-per-request model doesn't applies. Every Singleton reference used in your application is a client, when a client makes a request a new session is created.

Gabriel Aramburu
  • 2,951
  • 2
  • 16
  • 20
  • According to Oracle documentation - "Singleton session beans maintain their state between client invocations but are not required to maintain their state across server crashes or shutdowns" - so it seems it does maintains its state even after the response sent back to client. The more i look at it, the more i see it as an application bean. What do you think? – yapkm01 Dec 06 '13 at 14:37
  • You said 'Every Singleton reference used in your application is a client, when a client makes a request a new session is created'. But that's not what a singleton bean is. There's only 1 bean and there's no new singleton session bean instance be created for each request/response cycle. Every new request/response cycle uses the same singleton session bean. What you said will be true for stateless bean but i think not for singleton bean. – yapkm01 Dec 06 '13 at 20:19
  • here a session means a business transaction, I'm not saying that a new instance of a singleton session bean is created. – Gabriel Aramburu Dec 06 '13 at 20:56
  • there's something i don't understand. I see what you're saying the word 'session' being term as unit of work. If singleton session is of only 1 instance and its state can be maintained (and of course can be used in the request/response cycle), why is it that singleton session is always said being similiar to stateless session and not stateful bean? – yapkm01 Dec 10 '13 at 19:51
  • From [Java EE 7 ch.8](http://www.amazon.com/Beginning-Java-EE-Antonio-Goncalves/dp/143024626X): "Stateless and Singleton beans have in common the fact that they don't mantain conversational state with a dedicated client. Both bean types allow access by any client...Both share the same life cycle.." On the other hand, an stateful instance belongs to a unique client (reference) – Gabriel Aramburu Dec 11 '13 at 00:32
0
  • Stateless - Session lasts for a single client operation
  • Stateful - Session lasts across operations for a client
  • Singleton - Session lasts across clients an application
Brett Kail
  • 33,593
  • 2
  • 85
  • 90