SlideShare a Scribd company logo
1 of 19
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.

More Related Content

What's hot

Enterprise java unit-2_chapter-3
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3sandeep54552
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3sandeep54552
 
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction
Object-Oriented Analysis & Design (OOAD) Domain Modeling IntroductionDang Tuan
 
Enterprise java unit-2_chapter-1
Enterprise  java unit-2_chapter-1Enterprise  java unit-2_chapter-1
Enterprise java unit-2_chapter-1sandeep54552
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivityTanmoy Barman
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in javaGoogle
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and DesignHaitham El-Ghareeb
 
Object Oriented Design Concept
Object Oriented Design ConceptObject Oriented Design Concept
Object Oriented Design ConceptSharath g
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Peter R. Egli
 

What's hot (20)

Enterprise java unit-2_chapter-3
Enterprise  java unit-2_chapter-3Enterprise  java unit-2_chapter-3
Enterprise java unit-2_chapter-3
 
Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3Enterprise java unit-1_chapter-3
Enterprise java unit-1_chapter-3
 
Ooad unit – 1 introduction
Ooad unit – 1 introductionOoad unit – 1 introduction
Ooad unit – 1 introduction
 
JNDI
JNDIJNDI
JNDI
 
Java RMI
Java RMIJava RMI
Java RMI
 
Jsp lifecycle
Jsp   lifecycleJsp   lifecycle
Jsp lifecycle
 
Java rmi
Java rmiJava rmi
Java rmi
 
Iterative model
Iterative modelIterative model
Iterative model
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
Servlets
ServletsServlets
Servlets
 
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction  Object-Oriented Analysis & Design (OOAD)  Domain Modeling Introduction
Object-Oriented Analysis & Design (OOAD) Domain Modeling Introduction
 
Jdbc ppt
Jdbc pptJdbc ppt
Jdbc ppt
 
Enterprise java unit-2_chapter-1
Enterprise  java unit-2_chapter-1Enterprise  java unit-2_chapter-1
Enterprise java unit-2_chapter-1
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Event Handling in java
Event Handling in javaEvent Handling in java
Event Handling in java
 
Object Oriented Analysis and Design
Object Oriented Analysis and DesignObject Oriented Analysis and Design
Object Oriented Analysis and Design
 
Struts
StrutsStruts
Struts
 
Cohesion & Coupling
Cohesion & Coupling Cohesion & Coupling
Cohesion & Coupling
 
Object Oriented Design Concept
Object Oriented Design ConceptObject Oriented Design Concept
Object Oriented Design Concept
 
Remote Method Invocation (RMI)
Remote Method Invocation (RMI)Remote Method Invocation (RMI)
Remote Method Invocation (RMI)
 

Similar to Session bean

Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the startershohancse
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
Spring introduction
Spring introductionSpring introduction
Spring introductionLê 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 - TUT3287Ahmad Gohar
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questionsguest346cb1
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreDonald 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&6Lokesh Singrol
 
JAVA_BEAN.pptx
JAVA_BEAN.pptxJAVA_BEAN.pptx
JAVA_BEAN.pptxkoodalcsc
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4phanleson
 
Spring framework
Spring frameworkSpring framework
Spring frameworkAjit Koti
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionKelum Senanayake
 

Similar to Session bean (20)

Ejb3.1 for the starter
Ejb3.1 for the starterEjb3.1 for the starter
Ejb3.1 for the starter
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
Ch4 ejb
Ch4 ejbCh4 ejb
Ch4 ejb
 
Spring introduction
Spring introductionSpring introduction
Spring introduction
 
EJB 3.2 part 1
EJB 3.2 part 1EJB 3.2 part 1
EJB 3.2 part 1
 
J2 ee tutorial ejb
J2 ee tutorial ejbJ2 ee tutorial ejb
J2 ee tutorial ejb
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
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
 
The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
EJB Interview Questions
EJB Interview QuestionsEJB Interview Questions
EJB Interview Questions
 
Spring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-CoreSpring Framework Presantation Part 1-Core
Spring Framework Presantation Part 1-Core
 
Lecture 8 Enterprise Java Beans (EJB)
Lecture 8  Enterprise Java Beans (EJB)Lecture 8  Enterprise Java Beans (EJB)
Lecture 8 Enterprise Java Beans (EJB)
 
TY.BSc.IT Java QB U5
TY.BSc.IT Java QB U5TY.BSc.IT Java QB U5
TY.BSc.IT Java QB U5
 
Java bean
Java beanJava bean
Java bean
 
EJB 3.0 and J2EE
EJB 3.0 and J2EEEJB 3.0 and J2EE
EJB 3.0 and J2EE
 
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
 
JAVA_BEAN.pptx
JAVA_BEAN.pptxJAVA_BEAN.pptx
JAVA_BEAN.pptx
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 
Spring framework
Spring frameworkSpring framework
Spring framework
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 

More from sandeep54552

Dijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptxDijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptxsandeep54552
 
E_R-Diagram (2).pptx
E_R-Diagram (2).pptxE_R-Diagram (2).pptx
E_R-Diagram (2).pptxsandeep54552
 
Dijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxDijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxsandeep54552
 
YCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptYCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptsandeep54552
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptxsandeep54552
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptxsandeep54552
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxsandeep54552
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptxsandeep54552
 
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 introductionsandeep54552
 
Hill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligenceHill climbing algorithm in artificial intelligence
Hill climbing algorithm in artificial intelligencesandeep54552
 

More from sandeep54552 (20)

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

Recently uploaded

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxRaymartEstabillo3
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonJericReyAuditor
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfMahmoud M. Sallam
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxAnaBeatriceAblay2
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 

Recently uploaded (20)

EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptxEPANDING THE CONTENT OF AN OUTLINE using notes.pptx
EPANDING THE CONTENT OF AN OUTLINE using notes.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Science lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lessonScience lesson Moon for 4th quarter lesson
Science lesson Moon for 4th quarter lesson
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Pharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdfPharmacognosy Flower 3. Compositae 2023.pdf
Pharmacognosy Flower 3. Compositae 2023.pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptxENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
ENGLISH5 QUARTER4 MODULE1 WEEK1-3 How Visual and Multimedia Elements.pptx
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 

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.