SlideShare a Scribd company logo
1 of 15
EJB 3.1 Overview
Vladan Pulec
Agenda
 EJB features and functionality
 Brief demo
New Features
• Previous versions of EJBs suffered from:
– Heavyweight programming model
– Direct use of JNDI
– Verbose XML descriptor
• EJB 3 eliminates this by:
– Metadata annotations
– Minimal deployment descriptors (optional)
– Dependency injection
Component Types
EJB Technology
Session
(Stateless, stateful,
singleton)
Message-Driven
Session EJB Components:
• Business logic running within an EJB
Component
Message-Driven Beans:
• Asynchronous message consumer
• Different operational characteristics from
session beans
Entity EJBs:
• replaced by JPA (Java Persistence API)
•Supported only for backward compatibility
EJB Tiers
• Session beans act as a façade for the entity
components:
– Minimizes network overhead
– Clearer separation of concerns
• Design pattern (not mandated by Java EE
specification)
– Service tier (mostly session beans and message-driven
beans)
– Object-relational mapping tier (entity classes and
related supporting classes)
Session Façade Example
web EJB
Entity ClassesSession Beans
Client
Client
Client
FinanceSessionBean
PaymentSessionBean
Order
Payment
Credit Card
Authorization
Database
EJB Component Model
 Components are encapsulated within the EJB
container
 Container provides proxies to allow limited access
to the components
 Clients make calls to the interfaces (container
exposes proxies, not the actual beans)
 Container provides life-cycle management,
security, resource management, and transaction
management for the components
 Container also provides timer services and
monitors message queue (for message-driven
beans)
EJB Container
• Resource management
– Encapsulates access to external resources
– Connection pooling
• Life-cycle management
• Isolates implementation classes from clients
• Timer services
– scheduled work
• Monitors message queue
Embedded EJB Container (EJB lite)
 Subset of EJB functionality
 Added in Java EE 6
 Runs outside of an EJB container (using SDK only)
No application server required
 Supports stateless, stateful, and singleton
components
 Local and no interface only
 Synchronous invocation only
 Container-managed security and transactions
 Declarative and programmatic security
EJB Components
 Session Beans
Stateless
Stateful
Singleton
 Message-Driven Beans
Timer Service
• Container invokes either a stateless session
bean or Message-Driven bean
– Use timer service in the bean to configure the
timer
• Injected
• Via context
– Configure timing
– Configure timeout method
Difference between stateless and stateful session beans
EJB Objects
• EJB components are never called directly by
clients
• Clients get a reference to the component via
EJBObject, which acts as a proxy
– Stateful beans require separate proxies for each
call
– Stateless beans share the same proxy
Anatomy of a session bean
• Consists of an interface and implementation
class
• Must be a concrete class (cannot be final or
abstract)
• Must have no argument constructor
• Cannot start with “’ejb”
• Business and life-cycle methods
Session bean best practices
• Choose bean type carefully
– Stateless session beans fit most of the needs
• Examine interface types
– Remote interface require network access and will be
slow. Use local in using within the same JVM
• For DI, make sure not to inject stateful session
bean into a stateless bean
• Examine what kind of data will be stored in a
conversational state (stateful beans)
– Use primitive variables rather than large nested
composite objects

More Related Content

What's hot

Java.sql package
Java.sql packageJava.sql package
Java.sql packagemyrajendra
 
JDBC Architecture and Drivers
JDBC Architecture and DriversJDBC Architecture and Drivers
JDBC Architecture and DriversSimoniShah6
 
Middleware Services for Search, Online Ads and Recommender
Middleware Services for Search, Online Ads and RecommenderMiddleware Services for Search, Online Ads and Recommender
Middleware Services for Search, Online Ads and RecommenderYen-Yu Chen
 
J2EE and layered architecture
J2EE and layered architectureJ2EE and layered architecture
J2EE and layered architectureSuman Behara
 
XPages: The Next Step In Your Life As A Notes Developer
XPages: The Next Step In Your Life As A Notes DeveloperXPages: The Next Step In Your Life As A Notes Developer
XPages: The Next Step In Your Life As A Notes DeveloperPeter Presnell
 
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)Bojan Veljanovski
 
Java Training in Chennai
Java Training in Chennai Java Training in Chennai
Java Training in Chennai raj esaki
 
Complete integration with mule esb
Complete integration with mule esbComplete integration with mule esb
Complete integration with mule esbSon Nguyen
 
Domino X Pages
Domino X PagesDomino X Pages
Domino X Pagesddrschiw
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patternsalkuzaee
 
Getting Started with the NetBeans Platform
Getting Started with the NetBeans PlatformGetting Started with the NetBeans Platform
Getting Started with the NetBeans PlatformGeertjan Wielenga
 

What's hot (20)

Ejb intro
Ejb introEjb intro
Ejb intro
 
Java.sql package
Java.sql packageJava.sql package
Java.sql package
 
JDBC Architecture and Drivers
JDBC Architecture and DriversJDBC Architecture and Drivers
JDBC Architecture and Drivers
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Middleware Services for Search, Online Ads and Recommender
Middleware Services for Search, Online Ads and RecommenderMiddleware Services for Search, Online Ads and Recommender
Middleware Services for Search, Online Ads and Recommender
 
J2EE and layered architecture
J2EE and layered architectureJ2EE and layered architecture
J2EE and layered architecture
 
XPages: The Next Step In Your Life As A Notes Developer
XPages: The Next Step In Your Life As A Notes DeveloperXPages: The Next Step In Your Life As A Notes Developer
XPages: The Next Step In Your Life As A Notes Developer
 
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
Bojan Veljanovski - Modular Software Architecture and Design (Code Camp 2016)
 
Jdbc
JdbcJdbc
Jdbc
 
Mule ESB Fundamentals
Mule ESB FundamentalsMule ESB Fundamentals
Mule ESB Fundamentals
 
Java Training in Chennai
Java Training in Chennai Java Training in Chennai
Java Training in Chennai
 
Java ee introduction
Java ee introductionJava ee introduction
Java ee introduction
 
Mule esb overview
Mule esb overviewMule esb overview
Mule esb overview
 
Complete integration with mule esb
Complete integration with mule esbComplete integration with mule esb
Complete integration with mule esb
 
Domino X Pages
Domino X PagesDomino X Pages
Domino X Pages
 
Mule: Java Component
Mule: Java ComponentMule: Java Component
Mule: Java Component
 
Networking chapter IV
Networking chapter IVNetworking chapter IV
Networking chapter IV
 
Software Design Patterns
Software Design PatternsSoftware Design Patterns
Software Design Patterns
 
Neuro4j Workflow Overview
Neuro4j Workflow OverviewNeuro4j Workflow Overview
Neuro4j Workflow Overview
 
Getting Started with the NetBeans Platform
Getting Started with the NetBeans PlatformGetting Started with the NetBeans Platform
Getting Started with the NetBeans Platform
 

Viewers also liked

Android ui patterns
Android ui patternsAndroid ui patterns
Android ui patternsvpulec
 
Whats New in Jelly Bean
Whats New in Jelly BeanWhats New in Jelly Bean
Whats New in Jelly Beanvpulec
 
Java 8
Java 8Java 8
Java 8vpulec
 
Android ui patterns
Android ui patternsAndroid ui patterns
Android ui patternsMobile March
 
Java Web services
Java Web servicesJava Web services
Java Web servicesvpulec
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheLeslie Samuel
 

Viewers also liked (6)

Android ui patterns
Android ui patternsAndroid ui patterns
Android ui patterns
 
Whats New in Jelly Bean
Whats New in Jelly BeanWhats New in Jelly Bean
Whats New in Jelly Bean
 
Java 8
Java 8Java 8
Java 8
 
Android ui patterns
Android ui patternsAndroid ui patterns
Android ui patterns
 
Java Web services
Java Web servicesJava Web services
Java Web services
 
How to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your NicheHow to Become a Thought Leader in Your Niche
How to Become a Thought Leader in Your Niche
 

Similar to Enterprise beans

EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionKelum Senanayake
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecturetayab4687
 
Connecting ejb with mule
Connecting ejb with muleConnecting ejb with mule
Connecting ejb with muleRuman Khan
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJBPeter R. Egli
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabadrevanthonline
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questionsguest346cb1
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patternsAlassane Diallo
 
Session 2 Tp2
Session 2 Tp2Session 2 Tp2
Session 2 Tp2phanleson
 
Better Enterprise Integration With the WSO2 ESB 4.5.1
Better Enterprise Integration With the WSO2 ESB 4.5.1Better Enterprise Integration With the WSO2 ESB 4.5.1
Better Enterprise Integration With the WSO2 ESB 4.5.1WSO2
 

Similar to Enterprise beans (20)

EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
EJB 3.0 and J2EE
EJB 3.0 and J2EEEJB 3.0 and J2EE
EJB 3.0 and J2EE
 
EJB 3.1 by Bert Ertman
EJB 3.1 by Bert ErtmanEJB 3.1 by Bert Ertman
EJB 3.1 by Bert Ertman
 
Aravind vinnakota ejb_architecture
Aravind vinnakota ejb_architectureAravind vinnakota ejb_architecture
Aravind vinnakota ejb_architecture
 
Virtual classroom
Virtual classroomVirtual classroom
Virtual classroom
 
Connecting ejb with mule
Connecting ejb with muleConnecting ejb with mule
Connecting ejb with mule
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Enterprise Java Beans - EJB
Enterprise Java Beans - EJBEnterprise Java Beans - EJB
Enterprise Java Beans - EJB
 
Introcution to EJB
Introcution to EJBIntrocution to EJB
Introcution to EJB
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabad
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
enterprise java bean
enterprise java beanenterprise java bean
enterprise java bean
 
Real world java_ee_patterns
Real world java_ee_patternsReal world java_ee_patterns
Real world java_ee_patterns
 
Session 2 Tp2
Session 2 Tp2Session 2 Tp2
Session 2 Tp2
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Better Enterprise Integration With the WSO2 ESB 4.5.1
Better Enterprise Integration With the WSO2 ESB 4.5.1Better Enterprise Integration With the WSO2 ESB 4.5.1
Better Enterprise Integration With the WSO2 ESB 4.5.1
 

Recently uploaded

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 

Recently uploaded (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 

Enterprise beans

  • 2. Agenda  EJB features and functionality  Brief demo
  • 3. New Features • Previous versions of EJBs suffered from: – Heavyweight programming model – Direct use of JNDI – Verbose XML descriptor • EJB 3 eliminates this by: – Metadata annotations – Minimal deployment descriptors (optional) – Dependency injection
  • 4. Component Types EJB Technology Session (Stateless, stateful, singleton) Message-Driven Session EJB Components: • Business logic running within an EJB Component Message-Driven Beans: • Asynchronous message consumer • Different operational characteristics from session beans Entity EJBs: • replaced by JPA (Java Persistence API) •Supported only for backward compatibility
  • 5. EJB Tiers • Session beans act as a façade for the entity components: – Minimizes network overhead – Clearer separation of concerns • Design pattern (not mandated by Java EE specification) – Service tier (mostly session beans and message-driven beans) – Object-relational mapping tier (entity classes and related supporting classes)
  • 6. Session Façade Example web EJB Entity ClassesSession Beans Client Client Client FinanceSessionBean PaymentSessionBean Order Payment Credit Card Authorization Database
  • 7. EJB Component Model  Components are encapsulated within the EJB container  Container provides proxies to allow limited access to the components  Clients make calls to the interfaces (container exposes proxies, not the actual beans)  Container provides life-cycle management, security, resource management, and transaction management for the components  Container also provides timer services and monitors message queue (for message-driven beans)
  • 8. EJB Container • Resource management – Encapsulates access to external resources – Connection pooling • Life-cycle management • Isolates implementation classes from clients • Timer services – scheduled work • Monitors message queue
  • 9. Embedded EJB Container (EJB lite)  Subset of EJB functionality  Added in Java EE 6  Runs outside of an EJB container (using SDK only) No application server required  Supports stateless, stateful, and singleton components  Local and no interface only  Synchronous invocation only  Container-managed security and transactions  Declarative and programmatic security
  • 10. EJB Components  Session Beans Stateless Stateful Singleton  Message-Driven Beans
  • 11. Timer Service • Container invokes either a stateless session bean or Message-Driven bean – Use timer service in the bean to configure the timer • Injected • Via context – Configure timing – Configure timeout method
  • 12. Difference between stateless and stateful session beans
  • 13. EJB Objects • EJB components are never called directly by clients • Clients get a reference to the component via EJBObject, which acts as a proxy – Stateful beans require separate proxies for each call – Stateless beans share the same proxy
  • 14. Anatomy of a session bean • Consists of an interface and implementation class • Must be a concrete class (cannot be final or abstract) • Must have no argument constructor • Cannot start with “’ejb” • Business and life-cycle methods
  • 15. Session bean best practices • Choose bean type carefully – Stateless session beans fit most of the needs • Examine interface types – Remote interface require network access and will be slow. Use local in using within the same JVM • For DI, make sure not to inject stateful session bean into a stateless bean • Examine what kind of data will be stored in a conversational state (stateful beans) – Use primitive variables rather than large nested composite objects