SlideShare a Scribd company logo
Enterprise Java
Unit- 4
Chapter-2
Working with Session Beans
• Session Bean
• Types of Session Bean
• Remote and Local Interface
• Lifecycle of Enterprise Beans
• Packaging Enterprise Beans
Prof. Sandeep Vishwakarma
SESSION BEANS
• A Session Bean implements and encapsulates a
business task that can be invoked programmatically by
a client over local, remote, or web service client views.
• The session bean performs work (such as calculations
or database access) for its client by executing business
tasks inside the server.
• The application container or EJB container manages
the life cycle of the session bean instances. It notifies
the instances when bean action may be necessary, and
it provides a full range of services to ensure that the
session bean implementation is scalable and can
support a large number of clients.
TYPES OF SESSION BEANS
STATELESS SESSION BEAN
• Stateless Session Beans are business objects that do
not have state associated with them.
• The @Stateless annotation is used to mark the class
as Stateless Session Bean.
• Access to a single bean instance is still limited to only
one client at a time and concurrent access to the bean
is prohibited.
• Instance variables can be used but the contents of
those instance variables are not guaranteed to
be preserved across different client method calls.
• Instances of Stateless Session beans
are typically pooled because all stateless bean
instances are equivalent when they are not involved in
servicing a client-invoked method.
Examples
• Sending an e-mail to customer
• Adding an item to the database
• Getting a particular list of items from the
database
• Any operation which can be completed in
one single shot.
STATELESS SESSION BEAN LIFE CYCLE
STATELESS SESSION BEAN LIFE CYCLE STEPS
• A session bean instance’s life starts when a client obtains
a reference to a stateful session bean instance through
dependency injection or JNDI lookup.
• Stateless Session Bean is never passivated because it has
only two stages.
• The EJB Container creates and maintains a pool of
stateless session beans, beginning its lifecycle .
• The container performs any dependency injection and
then invokes the method annotated @PostConstruct .
• At the end of the life cycle , the EJB Container calls the
method annotated @PreDestroy , if it exists. The bean
instance is then ready for garbage collection
STATEFUL SESSION BEAN
• Stateful Session Beans are business objects with
@Stateful annotation .
• Stateful Session Beans keep track of which calling client
they are dealing with throughout a session.
• A session bean is not shared and access to the bean
instance is strictly limited to only one client at a time.
• When the client terminates, its session bean appears to
terminate and is no longer associated with the client.
• When the client invokes a method on the bean marked
with @Remove, it signals the end of the session with the
bean.
• If the client removes the bean, the session ends and the
state disappears.
Examples
• Shopping cart can be implemented by
Stateful session bean where the list of items
added to the cart by a user is stored in an
instance variable of session bean. When a
new item is added to the cart all the
previous items will still be maintained by
the bean until the session ends.
STATEFUL SESSION BEAN LIFE CYCLE
STATEFUL SESSION BEAN LIFE CYCLE STEPS
• A session bean instance’s life starts when a client obtains
a reference to a stateful session bean instance through
dependency injection or JNDI lookup.
• The container performs any dependency injection and
then invokes the method annotated @PostConstruct ,if
any. The bean is now ready to have its business methods.
• While in the ready stage, EJB Container may decide to
deactivate or passivate.
• EJB Container call @PrePassivate then call method
annotated @PostActivate.
• At the end of the life cycle , the client invoke a method
annotated @Remove and EJB Container calls method
anootated @PreDestroy if any. The bean instance is then
ready for garbage collection
SINGLETON SESSION BEAN
• Available from EJB 3.1, Singleton Session Beans are business
objects having a global shared state within a JVM.
• The @Singleton annotation is used to mark the class as
Singleton Session Bean.
• They are instantiated once per application and exist for the
lifecycle of the application.
• In cases where the container is distributed over many virtual
machines, each application will have one bean instance of the
Singleton for each JVM.
• It maintains its state between client invocations but that
state is not required to survive container shutdown or crash.
• A Singleton session bean is intended to be shared and
supports concurrent access by clients.
Examples
• Loading a global daily price list that will be the
same for every user might be done with a
singleton session bean, since this will prevent
the application having to do the same query
to a database over and over again.
• Application hit counter
SINGLETON SESSION BEAN LIFECYCLE
• A singleton session bean instance’s life starts
when the container invokes the newInstance method on
the session bean class to create the singleton bean
instance.
• Next, the container performs any dependency injection as
specified by the metadata annotations on the bean class or
by the deployment descriptor.
• If singleton is annotated with @Startup annotation then
container performs any dependency injection and invokes
@PostConstruct ,if any. The singleton bean instance is
now ready to have a business method by the client .
• At the end of the life cycle , the EJB Container calls the
method annotated @PreDestroy if exists. and EJB
Container calls method anootated @PreDestroy if any. The
singleton bean is now ready for garbage collection
What is a Message-Driven Bean?
• A message driven bean is a type of enterprise
bean, which is invoked by EJB container when it
receives a message from queue or topic. Message
driven bean is a stateless bean and is used to do
task asynchronously.
• A message-driven bean is an enterprise bean that
allows Java EE applications to process messages
asynchronously. This type of bean normally acts
as a JMS message listener, which is similar to an
event listener but receives JMS messages instead
of events.
Characteristics of Message-driven beans
• They execute upon receipt of a single client message.
• They are invoked asynchronously.
• They are relatively short-lived.
• They do not represent directly shared data in the
database, but they can access and update this data.
• They can be transaction-aware.
• They are stateless.
Message-Driven Bean Life Cycle
Message-Driven Bean Life Cycle steps
• A message-driven bean instance’s life starts when
the container invokes newInstance on the message-driven
bean class to create a new instance.
• Next, the container injects the bean’s MessageDrivenContext, if
applicable, and performs any other dependency injection as
specified by metadata .
• The container then calls the bean’s PostConstruct
lifecycle callback methods, if any.
• The message-driven bean instance is now ready to be delivered
a message sent to its associated destination or endpoint by any
client.
• When the container no longer needs the instance , the
container invokes the PreDestroy lifecycle callback
methods for it, if any. This ends the life of the message-driven
bean instance.
Ad

More Related Content

What's hot (20)

Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1
sandeep54552
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
suraj pandey
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3
sandeep54552
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
Vikas Jagtap
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
Edureka!
 
Memory Management & Garbage Collection
Memory Management & Garbage CollectionMemory Management & Garbage Collection
Memory Management & Garbage Collection
Abhishek Sur
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
Return on Intelligence
 
Shadow paging
Shadow pagingShadow paging
Shadow paging
GowriLatha1
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 
Deadlock ppt
Deadlock ppt Deadlock ppt
Deadlock ppt
Sweetestangel Kochar
 
Component based software engineering
Component based software engineeringComponent based software engineering
Component based software engineering
Charotar University Of Science And Technology,Gujrat
 
Introduction to Visual Studio.NET
Introduction to Visual Studio.NETIntroduction to Visual Studio.NET
Introduction to Visual Studio.NET
Dutch Dasanaike {LION}
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
sandeep54552
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
naveen kumar
 
EJB .
EJB .EJB .
EJB .
ayyagari.vinay
 
Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1Enterprise java unit-1_chapter-1
Enterprise java unit-1_chapter-1
sandeep54552
 
Graphical User Interface in JAVA
Graphical User Interface in JAVAGraphical User Interface in JAVA
Graphical User Interface in JAVA
suraj pandey
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3
sandeep54552
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
arvind pandey
 
Introduction to Java Programming
Introduction to Java ProgrammingIntroduction to Java Programming
Introduction to Java Programming
Ravi Kant Sahu
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
Edureka!
 
Memory Management & Garbage Collection
Memory Management & Garbage CollectionMemory Management & Garbage Collection
Memory Management & Garbage Collection
Abhishek Sur
 
Jdbc architecture and driver types ppt
Jdbc architecture and driver types pptJdbc architecture and driver types ppt
Jdbc architecture and driver types ppt
kamal kotecha
 
Data Types, Variables, and Operators
Data Types, Variables, and OperatorsData Types, Variables, and Operators
Data Types, Variables, and Operators
Marwa Ali Eissa
 
Asp.net state management
Asp.net state managementAsp.net state management
Asp.net state management
priya Nithya
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
sandeep54552
 
Gof design pattern
Gof design patternGof design pattern
Gof design pattern
naveen kumar
 

Similar to Session bean (20)

Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the starter
shohancse
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
Emprovise
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
Raghavendra Goud
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
Lê Hảo
 
EJB 3.2 part 1
EJB 3.2 part 1EJB 3.2 part 1
EJB 3.2 part 1
megrhi haikel
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
Niraj Bharambe
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
Krishna900061
 
CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287
Ahmad Gohar
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
Simon Ritter
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
guest346cb1
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-Core
Donald Lika
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
Fahad Golra
 
TY.BSc.IT Java QB U5
TY.BSc.IT Java QB U5TY.BSc.IT Java QB U5
TY.BSc.IT Java QB U5
Lokesh Singrol
 
Java bean
Java beanJava bean
Java bean
Jafar Nesargi
 
EJB 3.0 and J2EE
EJB 3.0 and J2EEEJB 3.0 and J2EE
EJB 3.0 and J2EE
Aniruddha Ray (Ani)
 
TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6
Lokesh Singrol
 
JAVA_BEAN.pptx
JAVA_BEAN.pptxJAVA_BEAN.pptx
JAVA_BEAN.pptx
koodalcsc
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
phanleson
 
Spring framework
Spring frameworkSpring framework
Spring framework
Ajit Koti
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
Kelum Senanayake
 
Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the starter
shohancse
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
Emprovise
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
Lê Hảo
 
CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287CDI Best Practices with Real-Life Examples - TUT3287
CDI Best Practices with Real-Life Examples - TUT3287
Ahmad Gohar
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
Simon Ritter
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
guest346cb1
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-Core
Donald Lika
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
Fahad Golra
 
TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6TY.BSc.IT Java QB U5&6
TY.BSc.IT Java QB U5&6
Lokesh Singrol
 
JAVA_BEAN.pptx
JAVA_BEAN.pptxJAVA_BEAN.pptx
JAVA_BEAN.pptx
koodalcsc
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
phanleson
 
Spring framework
Spring frameworkSpring framework
Spring framework
Ajit Koti
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
Kelum Senanayake
 
Ad

More from sandeep54552 (20)

Dijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptxDijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptx
sandeep54552
 
E_R-Diagram (2).pptx
E_R-Diagram (2).pptxE_R-Diagram (2).pptx
E_R-Diagram (2).pptx
sandeep54552
 
Dijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxDijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptx
sandeep54552
 
DFS_New.pptx
DFS_New.pptxDFS_New.pptx
DFS_New.pptx
sandeep54552
 
Agents_AI.ppt
Agents_AI.pptAgents_AI.ppt
Agents_AI.ppt
sandeep54552
 
YCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptYCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.ppt
sandeep54552
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptx
sandeep54552
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptx
sandeep54552
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
sandeep54552
 
Heap_Sort1.pptx
Heap_Sort1.pptxHeap_Sort1.pptx
Heap_Sort1.pptx
sandeep54552
 
Quick_sort1.pptx
Quick_sort1.pptxQuick_sort1.pptx
Quick_sort1.pptx
sandeep54552
 
Link_List.pptx
Link_List.pptxLink_List.pptx
Link_List.pptx
sandeep54552
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
sandeep54552
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
sandeep54552
 
Exception handling in c++
Exception handling in c++Exception handling in c++
Exception handling in c++
sandeep54552
 
Inheritance in c++
Inheritance in c++ Inheritance in c++
Inheritance in c++
sandeep54552
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
sandeep54552
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
Jsp tag library
Jsp tag libraryJsp tag library
Jsp tag library
sandeep54552
 
Dijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptxDijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptx
sandeep54552
 
E_R-Diagram (2).pptx
E_R-Diagram (2).pptxE_R-Diagram (2).pptx
E_R-Diagram (2).pptx
sandeep54552
 
Dijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxDijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptx
sandeep54552
 
YCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptYCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.ppt
sandeep54552
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptx
sandeep54552
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptx
sandeep54552
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
sandeep54552
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
sandeep54552
 
Exception handling in c++
Exception handling in c++Exception handling in c++
Exception handling in c++
sandeep54552
 
Inheritance in c++
Inheritance in c++ Inheritance in c++
Inheritance in c++
sandeep54552
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
sandeep54552
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
Ad

Recently uploaded (20)

Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 4-30-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 4-30-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdfBiophysics Chapter 3 Methods of Studying Macromolecules.pdf
Biophysics Chapter 3 Methods of Studying Macromolecules.pdf
PKLI-Institute of Nursing and Allied Health Sciences Lahore , Pakistan.
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptxYSPH VMOC Special Report - Measles Outbreak  Southwest US 5-3-2025.pptx
YSPH VMOC Special Report - Measles Outbreak Southwest US 5-3-2025.pptx
Yale School of Public Health - The Virtual Medical Operations Center (VMOC)
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx2541William_McCollough_DigitalDetox.docx
2541William_McCollough_DigitalDetox.docx
contactwilliamm2546
 
P-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 finalP-glycoprotein pamphlet: iteration 4 of 4 final
P-glycoprotein pamphlet: iteration 4 of 4 final
bs22n2s
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Anti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptxAnti-Depressants pharmacology 1slide.pptx
Anti-Depressants pharmacology 1slide.pptx
Mayuri Chavan
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulsepulse  ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
pulse ppt.pptx Types of pulse , characteristics of pulse , Alteration of pulse
sushreesangita003
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 

Session bean

  • 1. Enterprise Java Unit- 4 Chapter-2 Working with Session Beans • Session Bean • Types of Session Bean • Remote and Local Interface • Lifecycle of Enterprise Beans • Packaging Enterprise Beans Prof. Sandeep Vishwakarma
  • 2. SESSION BEANS • A Session Bean implements and encapsulates a business task that can be invoked programmatically by a client over local, remote, or web service client views. • The session bean performs work (such as calculations or database access) for its client by executing business tasks inside the server. • The application container or EJB container manages the life cycle of the session bean instances. It notifies the instances when bean action may be necessary, and it provides a full range of services to ensure that the session bean implementation is scalable and can support a large number of clients.
  • 4. STATELESS SESSION BEAN • Stateless Session Beans are business objects that do not have state associated with them. • The @Stateless annotation is used to mark the class as Stateless Session Bean. • Access to a single bean instance is still limited to only one client at a time and concurrent access to the bean is prohibited. • Instance variables can be used but the contents of those instance variables are not guaranteed to be preserved across different client method calls. • Instances of Stateless Session beans are typically pooled because all stateless bean instances are equivalent when they are not involved in servicing a client-invoked method.
  • 5. Examples • Sending an e-mail to customer • Adding an item to the database • Getting a particular list of items from the database • Any operation which can be completed in one single shot.
  • 7. STATELESS SESSION BEAN LIFE CYCLE STEPS • A session bean instance’s life starts when a client obtains a reference to a stateful session bean instance through dependency injection or JNDI lookup. • Stateless Session Bean is never passivated because it has only two stages. • The EJB Container creates and maintains a pool of stateless session beans, beginning its lifecycle . • The container performs any dependency injection and then invokes the method annotated @PostConstruct . • At the end of the life cycle , the EJB Container calls the method annotated @PreDestroy , if it exists. The bean instance is then ready for garbage collection
  • 8. STATEFUL SESSION BEAN • Stateful Session Beans are business objects with @Stateful annotation . • Stateful Session Beans keep track of which calling client they are dealing with throughout a session. • A session bean is not shared and access to the bean instance is strictly limited to only one client at a time. • When the client terminates, its session bean appears to terminate and is no longer associated with the client. • When the client invokes a method on the bean marked with @Remove, it signals the end of the session with the bean. • If the client removes the bean, the session ends and the state disappears.
  • 9. Examples • Shopping cart can be implemented by Stateful session bean where the list of items added to the cart by a user is stored in an instance variable of session bean. When a new item is added to the cart all the previous items will still be maintained by the bean until the session ends.
  • 10. STATEFUL SESSION BEAN LIFE CYCLE
  • 11. STATEFUL SESSION BEAN LIFE CYCLE STEPS • A session bean instance’s life starts when a client obtains a reference to a stateful session bean instance through dependency injection or JNDI lookup. • The container performs any dependency injection and then invokes the method annotated @PostConstruct ,if any. The bean is now ready to have its business methods. • While in the ready stage, EJB Container may decide to deactivate or passivate. • EJB Container call @PrePassivate then call method annotated @PostActivate. • At the end of the life cycle , the client invoke a method annotated @Remove and EJB Container calls method anootated @PreDestroy if any. The bean instance is then ready for garbage collection
  • 12. SINGLETON SESSION BEAN • Available from EJB 3.1, Singleton Session Beans are business objects having a global shared state within a JVM. • The @Singleton annotation is used to mark the class as Singleton Session Bean. • They are instantiated once per application and exist for the lifecycle of the application. • In cases where the container is distributed over many virtual machines, each application will have one bean instance of the Singleton for each JVM. • It maintains its state between client invocations but that state is not required to survive container shutdown or crash. • A Singleton session bean is intended to be shared and supports concurrent access by clients.
  • 13. Examples • Loading a global daily price list that will be the same for every user might be done with a singleton session bean, since this will prevent the application having to do the same query to a database over and over again. • Application hit counter
  • 15. • A singleton session bean instance’s life starts when the container invokes the newInstance method on the session bean class to create the singleton bean instance. • Next, the container performs any dependency injection as specified by the metadata annotations on the bean class or by the deployment descriptor. • If singleton is annotated with @Startup annotation then container performs any dependency injection and invokes @PostConstruct ,if any. The singleton bean instance is now ready to have a business method by the client . • At the end of the life cycle , the EJB Container calls the method annotated @PreDestroy if exists. and EJB Container calls method anootated @PreDestroy if any. The singleton bean is now ready for garbage collection
  • 16. What is a Message-Driven Bean? • A message driven bean is a type of enterprise bean, which is invoked by EJB container when it receives a message from queue or topic. Message driven bean is a stateless bean and is used to do task asynchronously. • A message-driven bean is an enterprise bean that allows Java EE applications to process messages asynchronously. This type of bean normally acts as a JMS message listener, which is similar to an event listener but receives JMS messages instead of events.
  • 17. Characteristics of Message-driven beans • They execute upon receipt of a single client message. • They are invoked asynchronously. • They are relatively short-lived. • They do not represent directly shared data in the database, but they can access and update this data. • They can be transaction-aware. • They are stateless.
  • 19. Message-Driven Bean Life Cycle steps • A message-driven bean instance’s life starts when the container invokes newInstance on the message-driven bean class to create a new instance. • Next, the container injects the bean’s MessageDrivenContext, if applicable, and performs any other dependency injection as specified by metadata . • The container then calls the bean’s PostConstruct lifecycle callback methods, if any. • The message-driven bean instance is now ready to be delivered a message sent to its associated destination or endpoint by any client. • When the container no longer needs the instance , the container invokes the PreDestroy lifecycle callback methods for it, if any. This ends the life of the message-driven bean instance.