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 (20)

JNDI
JNDIJNDI
JNDI
 
Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)Enterprise JavaBeans(EJB)
Enterprise JavaBeans(EJB)
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
Cookies in servlet
Cookies in servletCookies in servlet
Cookies in servlet
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 
Servlets
ServletsServlets
Servlets
 
Java Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and StreamsJava Course 8: I/O, Files and Streams
Java Course 8: I/O, Files and Streams
 
Servlets
ServletsServlets
Servlets
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java RMI
Java RMIJava RMI
Java RMI
 
Introduction to EJB
Introduction to EJBIntroduction to EJB
Introduction to EJB
 
JVM
JVMJVM
JVM
 
Chapter 3 servlet & jsp
Chapter 3 servlet & jspChapter 3 servlet & jsp
Chapter 3 servlet & jsp
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
Rmi presentation
Rmi presentationRmi presentation
Rmi presentation
 
Java beans
Java beansJava beans
Java beans
 
MULTI THREADING IN JAVA
MULTI THREADING IN JAVAMULTI THREADING IN JAVA
MULTI THREADING IN JAVA
 
Java Beans
Java BeansJava Beans
Java Beans
 
Implicit object.pptx
Implicit object.pptxImplicit object.pptx
Implicit object.pptx
 

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
 

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
 
Jsp tag library
Jsp tag libraryJsp tag library
Jsp tag library
 

Recently uploaded

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17Celine George
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 

Recently uploaded (20)

2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17How to Add New Custom Addons Path in Odoo 17
How to Add New Custom Addons Path in Odoo 17
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 

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.