• ↑↓ pour naviguer
  • pour ouvrir
  • pour sélectionner
  • ⌘ ⌥ ↵ pour ouvrir dans un panneau
  • ←→ pour naviguer
  • esc pour rejeter
⌘ '
raccourcis clavier

Overview

Session beans are business process objects in EJB. They come in two flavors—stateful and stateless—each designed for different types of conversations with clients.

Comparison

FeatureStateful Session BeanStateless Session Bean
Conversational StateRetained across multiple method callsNone retained between calls
Client RelationshipDedicated one-to-one bean per clientShared pool, any instance can serve any client
LifetimeMatches client sessionSingle method call
Memory ManagementPassivation/Activation for memory savingsNo passivation needed
Instance PoolingNot pooled (each is unique)Pooled and reused
ScalabilityHeavy, limited scalabilityLightweight, highly scalable
Use CasesShopping carts, multi-step forms, banking transactionsCredit card verification, calculations, web services

When to Use

Use Stateful When:

  • Business process spans multiple method invocations
  • Must remember client data across requests
  • Examples: e-commerce shopping cart, multi-step loan application

Use Stateless When:

  • Each request is independent
  • Need high scalability
  • Examples: rate calculation, data validation, report generation

Key Insight

The fundamental difference is whether the conversation spans one request or multiple requests. Stateless beans are like stateless HTTP—they don’t remember previous interactions. Stateful beans maintain the conversation state, like a logged-in user’s session.