SlideShare a Scribd company logo
1 of 56
Download to read offline
Enterprise JavaBeans (EJB 3.x)
Fahad R. Golra
ECE Paris Ecole d'Ingénieurs - FRANCE
Lecture 8 - Enterprise Java
Beans (EJB)
• Introduction to EJBs
• Types of EJBs
• Session Beans
• Message Driven Beans
• Transaction Management
2 JEE - Enterprise Java Beans
3 Layers of Information System
3 JEE - Enterprise Java Beans
presentation
layer
application logic
layer
resource management
layer
Client
informationsystem
EJB
JSP JSF
Servlets
JPA
Database
Java EE Server
• The runtime portion of a Java EE product. A Java EE server
provides EJB and web containers.
4 JEE - Enterprise Java Beans
When to use EJB?
• If the application needs
• to be scalable
• a transactional context
• diversity of clients
5 JEE - Enterprise Java Beans
Why to use EJBs
• Encapsulate business logic
• multi-tier architecture
• Remote access
• apps on different servers can access them
• Simplicity
• simpler than other remote object systems
• Broad vendor support
• JBoss, Oracle AS, WebLogic, WepSphere
• Scalability
• support for clustering, load-balancing and failover
6 JEE - Enterprise Java Beans
Why EJB 3.x
• Network connections between the clients and the
EJBs
• Naming services (JNDI)
• Transactions
• Persistence and the management of DB pool of
connections
• Distribution
• Security
• Management of component’s life cycle
7 JEE - Enterprise Java Beans
Types of EJB
8
EJB
Message-Driven
Session
Entity
(pruned)
[JPA]
StatelessStateful
Container
Managed
Persistence
Bean
Managed
Persistence
Singleton
Bean Type Annotation
Session Bean Performs a task for a client; optionally, may implement
a web service
Message-
driven Bean
Acts as a listener for a particular messaging type,
such as the Java Message Service API
Stateless Session Beans
• Used when
• The bean's state has no data for a specific client.
• In a single method invocation, the bean performs a
generic task for all clients. For example, you might
use a stateless session bean to send an email that
confirms an online order.
• The bean implements a web service.
9 JEE - Enterprise Java Beans
Stateless Session Beans
10 JEE - Enterprise Java Beans
Java EE Server
EJB Container
Stateless Bean Pool
Bean
Instance
Bean
Instance
Bean
Instance
client Random
A random bean instance is selected from the pool
Stateful Session Beans
• Used when the following conditions are true
• The bean's state represents the interaction between
the bean and a specific client.
• The bean needs to hold information about the client
across method invocations.
• The bean mediates between the client and the other
components of the application, presenting a
simplified view to the client.
• Behind the scenes, the bean manages the work
flow of several enterprise beans.
11 JEE - Enterprise Java Beans
Stateful Session Beans
12 JEE - Enterprise Java Beans
Java EE Server
EJB Container
Bean
Instance
Bean
Instance
Bean
Instance
client C
client B
client A
One bean instance per client
Singleton Session Beans
• They are used when
• State needs to be shared across the application.
• A single enterprise bean needs to be accessed by
multiple threads concurrently.
• The application needs an enterprise bean to
perform tasks upon application startup and
shutdown.
• The bean implements a web service.
13 JEE - Enterprise Java Beans
Singleton Session Beans
14 JEE - Enterprise Java Beans
Java EE Server
EJB Container
Bean
Instance
client C
client B
client A
One bean instance per application server instance
Category Related Annotations
15 JEE - Enterprise Java Beans
Bean Type Annotation
Session Bean @Stateless
@Stateful
@Singleton
Message-driven Bean @MessageDriven
JPA Entities @Entity*
@EntityManager*
Contents of EJB
• Enterprise bean class:
• business methods of the enterprise bean
• any lifecycle callback methods.
• Business interfaces:
• define the business methods
• not required if the enterprise bean exposes a local,
no-interface view
• Helper classes:
• other classes needed by the enterprise bean class,
such as exception and utility classes.
16 JEE - Enterprise Java Beans
Remote & Local Access
17 JEE - Enterprise Java Beans
presentation
layer
application logic
layer
resource management
layer
Client
informationsystem
EJB A
JSP JSF
Servlets
JPA
DatabaseJava EE Server
EJB B
Desktop app
Legend:
Local client
Remote client
Access Mode Annotations
18 JEE - Enterprise Java Beans
Bean Type Annotation
Session Bean @Local
@Remote
@LocalBean*
@WebService
Message-driven Bean @WebService
JPA Entities N/A
Remote & Local Access
• Whether to allow local or remote access depends on
the following factors.
• Tight or loose couple of related beans
• Type of client: web components on the same server
or application clients, etc.
• Component Distribution: A scalable server on
multiple servers
• Performance: Remote calls may be slower than
local calls. Distributed computing on different
servers for performance.
19 JEE - Enterprise Java Beans
EJB Business Interfaces
• Local Interface
@Local
public interface MyStatelessBeanLocal {
String sayHello(String name);
}
• Remote Interface
@Remote
public interface MyStatelessBeanRemote {
String sayHello(String name);
}
20
Stateless Session Beans
• Each invocation of a stateless business method is
independent from previous invocations
• Because stateless session beans are "stateless" they
tend to process requests faster and use less
resources
• All instances are equivalent – the EJB container can
assign a pooled stateless bean instance to any client,
improving scalability
21 JEE - Enterprise Java Beans
Stateless session bean lifecycle
22 JEE - Enterprise Java Beans
NON
EXISTENT
READY
• Create new bean instance
• DI on bean, if any
• @PostConstruct, if any
• @PreDestroy, if any
Client
DI or JNDI lookup
Instances are removed automatically from the pool by the container
Example Hello Bean (Stateless)
@Stateless
@Local(MyStatelessBeanLocal.class)
@Remote(MyStatelessBeanRemote.class)
public class MyStatelessBean implements MyStatelessBeanRemote,
MyStatelessBeanLocal {
public MyStatelessBean() {
// TODO Auto-generated constructor stub
}
@Override
public String sayHello(String name) {
return "hello, " + name;
}
}
23 JEE - Enterprise Java Beans
JNDI Lookup
• Clients find the bean via JNDI
• Client Java code doesn’t even know the machine on which the
bean resides
• Clients use the bean like a normal POJO
• But arguments and return values are sent across network ︎
So, custom classes should be Serializable
InitialContext context = new InitialContext();
InterfaceName bean =(InterfaceName)context.lookup("JNDI- Name");
• jndi.properties
• ︎Text file in classpath; gives remote URL and other info
24 JEE - Enterprise Java Beans
Accessing Local EJB
• Dependency Injection
@EJB
MyStatelessBeanLocal myDIBeanLocal;
• JNDI Lookup
Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES,
"org.jboss.ejb.client.naming");
Context context = new InitialContext(jndiProperties);
MyStatelessBeanLocal myJNDIBeanLocal = (MyStatelessBeanLocal)
context.lookup(“java:module/MyStatelessBean!
com.ece.jee.MyStatelessBeanLocal”);
• Clients do not use the new operator to obtain a new instance
25 JEE - Enterprise Java Beans
Accessing Remote EJB
• Dependency Injection
@EJB
MyStatelessBeanRemote myDIBeanRemote;
• JNDI Lookup
Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES,
"org.jboss.ejb.client.naming");
Context context = new InitialContext(jndiProperties);
MyStatelessBeanLocal myJNDIBeanLocal = (MyStatelessBeanLocal)
context.lookup(“java:module/MyStatelessBean!
com.ece.jee.MyStatelessBeanLocal”);
• Clients do not use the new operator to obtain a new instance
26 JEE - Enterprise Java Beans
Portable JNDI Syntax
• java:global
• JNDI namespace for remote EJBs
java:global[/application name]/module name /enterprise bean name[/
interface name ]
• java:module
• JNDI namespace for local EJBs within the same module.
java:module/enterprise bean name/[interface name]
• java:app
• JNDI namespace is used to look up local EJBs packaged within the
same application.
java:app[/module name]/enterprise bean name [/interface name]
27 JEE - Enterprise Java Beans
Stateful Session Beans
• POJOs
• Instance of the Bean relates to a specific client (in memory while
he/she is connected)
• Expires in case of inactivity (similar to session in Servlet/Jsp)
• Ordinary Java classes; no special interfaces or parent classes. 

• Local or remote access
• Can be accessed either on local app server or remote app server
• Session Expiry
• ︎ The Session expires after the method annotated with
@Remove is executed
• Session can also expire in case of a time-out
28 JEE - Enterprise Java Beans
Stateful session bean lifecycle
29 JEE - Enterprise Java Beans
NON
EXISTENT
READY PASSIVE
• Create new bean instance
• DI on bean, if any
• @PostConstruct, if any
Before instance passivation
• @PrePassivate, if any
After instance activation
• @PostActivate, if any
• @Remove*
• @PreDestroy, if any
Client
DI or JNDI lookup
* Method called by the client code, other methods are called by container
Callback method annotations
@PostConstruct
public void initialize() { ... at Bean’s initialization ... }
@PreDestroy
• public void destroy() { ... destruction of Bean ... }
@PrePassivate //only for Stateful beans
public void beforeSwap() { ... to do before Bean is passivated ... }
@PostActivate //only for Stateful beans
public void afterSwap() { ... to do after Bean is activated ... }
30 JEE - Enterprise Java Beans
@Remove
• Container does not manage a pool for Stateful EJBs
• If the instance is not removed it stays in the memory
• A timeout from the server destroys the bean instance
from READ or PASSIVE state
• A method with @Remove annotation is used to
manage the destruction of instance
@Remove
public void destroy(){
}
31 JEE - Enterprise Java Beans
Singleton Session Beans
• Only one instance is created per bean
• All clients use the same instance
• @Startup loads it, when server starts
• Concurrency can be managed by two ways
• Container Managed Concurrency
• Bean Managed Concurrency
• Bean Concurrency
@ConcurrencyManagement(ConcurrencyManagementType.BEAN)
public class MySingleton {
Use synchronised, volatile, etc.
32 JEE - Enterprise Java Beans
Container Managed Concurrency
• Uses READ and WRITE locks
• WRITE lock: No other READ or WRITE method can be
executed concurrently
• READ lock: Only READ lock methods can be executed
concurrently
• Default concurrency management is Container
• Default lock for all methods is WRITE lock
33 JEE - Enterprise Java Beans
Container Managed Concurrency
@ConcurrencyManagement(ConcurrencyManagementType.CONTAINER)
public class MySingleton {
@Lock(LockType.WRITE)
public void myMethod1() {}
@Lock(LockType.READ)
public void myMethod2() {}
}
34 JEE - Enterprise Java Beans
Singleton session bean lifecycle
35 JEE - Enterprise Java Beans
NON
EXISTENT
READY
• @Startup, create new bean instance
• DI on bean, if any
• @PostConstruct, if any
• @PreDestroy, if any
EJB Container
EJB and Web Services
• A client can access a JavaEE application through
• JAX-WS web service
• Business methods of EJB
@Stateless
@WebService
public class HelloServiceBean {
private final String message = "Hello, ";
public void HelloServiceBean() {
}
@WebMethod
public String sayHello(String name) {
return message + name + ".";
}
}
36 JEE - Enterprise Java Beans
Message-Driven Vs Stateless Beans
• Resemblances
• Retain no data or conversational state for a specific
client.
• All instances are equivalent. EJB container can
• assign a message to any message-driven bean
instance
• pool these instances to allow streams of
messages to be processed concurrently
• A single message-driven bean can process
messages from multiple clients.
37 JEE - Enterprise Java Beans
Message-Driven Vs Stateless Beans
• Differences
• clients do not access message-driven beans
through interfaces
• contain some state across the handling of client
messages,
• JMS API connection, an open database
connection, etc.
• client access through JMS
• by sending messages to the message
destination for which the message-driven bean
class is the MessageListener.
38 JEE - Enterprise Java Beans
Message Driven Bean
• They have the following characteristics
• 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.
39 JEE - Enterprise Java Beans
Message-driven bean lifecycle
40 JEE - Enterprise Java Beans
NON
EXISTENT
READY
• DI on bean, if any
• Create new bean instance
• @PostConstruct, if any
• @PreDestroy, if any
• Destroy the bean instance
• onMessage
Message-driven bean
• JMS (java.sun.com/jms)
• Two mothers of communication
• Queue : Thread of discussion (one consumer)
• Topic : Topic of discussion (diffusion)
• ConnectionFactory : Factory of connections towards queue/topic
• Connection : connection towards queue/topic
• Session :
• Creation of an sender and of a receiver ︎
• Can be transactional
41 JEE - Enterprise Java Beans
Message Driven Bean
@MessageDriven(activationConfig ={
@ActivationConfigProperty( propertyName = "destination",
propertyValue = "topic_ece"),
@ActivationConfigProperty( propertyName = "destinationType",
propertyValue = "javax.jms.Topic")})
public class Mdb implements MessageListener {
public void onMessage(Message inMessage) {
System.out.println(((TextMessage)msg).getText());
}
}
42
Message Driven Bean (Sender)
@Resource(name="rigolo", mappedName="topic_rigolo")
Topic topic;

@Resource(name="factory", mappedName="JTCF")
TopicConnectionFactory factory;

TopicSession session;

TopicPublisher sender;
public void publish(String value) {

TopicConnection tc = factory.createTopicConnection();
session = tc.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
sender = session.createPublisher(topic);
TextMessage msg = session.createTextMessage();
msg.setText("MDB: " + value);
sender.publish(msg);
}
43
Transaction Management
• Business Transaction
• Interaction in real world
• Usually between enterprise & person or between enterprises
• Information processing that is divided into individual,
indivisible operations, called transactions
• Performs function on (shared) database
44 JEE - Enterprise Java Beans
The ACID Properties
• A set of properties that guarantee that transactions
are processed reliably
• Atomicity
• Consistency
• Isolation
• Durability
45 JEE - Enterprise Java Beans
Atomicity
• All (commit) or nothing (abort)
• "all or nothing": if one part of the transaction fails, the
entire transaction fails
• Example: transfer money between two bank accounts
• Must handle situations including power failures,
errors, and crashes
46 JEE - Enterprise Java Beans
Consistency
• Each transaction takes valid states to valid states:
• Satisfy integrity constraints, triggers
• Sometimes the only notion of “valid” state is “a state
that could have been produced by executing a
sequence of transactions
47 JEE - Enterprise Java Beans
Isolation
• Each transaction behaves as if it were executed in
isolation at some instant in time
• AKA Serializability
• Ensures that the concurrent execution of transactions
results in a system state that would be obtained if
transactions were executed serially
• Consistency + Isolation implies the data remains
consistent even when multiple transaction programs
execute concurrently
48 JEE - Enterprise Java Beans
Durability
• The effect of a committed transaction will not be lost
• Even in the event of power loss, crashes, or errors
• So data must be on stable storage before commit
• Usually done with a log (or journal) that must be
forced before commit and used in case of crash
recovery
49 JEE - Enterprise Java Beans
Transactions
• There are two types of transactions
• Local Transactions
• They span only on a single resource
• Global Transactions (JTA Transactions)
• They span on multiple resources
• Default transaction in Java EE
• Two management styles
• Container managed transactions (default)
• Bean managed transactions
50 JEE - Enterprise Java Beans
Management Mode Annotations
51 JEE - Enterprise Java Beans
Bean Type Annotation
Transactions @TransactionManagement (CONTAINER)
@TransactionManagement (BEAN)
Security @RunAs()
@RolesAllowed
Bean Managed Transactions
• Manually manage the transaction
@TransactionManagement(TransactionManagementType.BEAN)
public class MyBean {
@Resource
private UserTransaction tx;
public void myMethod() {
try {
tx.begin();
methodcall1();
methodcall2();
methodcall3();
tx.commit();
} catch (Exception e) {
e.printStackTrace();}
}
}
52 JEE - Enterprise Java Beans
Contrainer Managed Transactions
• The start and stop of transactions is managed by
container
@TransactionManagement(TransactionManagementType.CONTAINER)
public class MyTester {
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void myMethod() {
methodcall1();
methodcall2();
methodcall3();
}
}
53 JEE - Enterprise Java Beans
Transaction Attributes
• REQUIRED
• Client in transaction: uses transaction
• Client without transaction: creates new transaction
• REQUIRES_NEW
• Client in transaction: creates new transaction
• Client without transaction: creates new transaction
• MANDATORY
• Client in transaction: uses transaction
• Client without transaction: throws exception
54 JEE - Enterprise Java Beans
Transaction Attributes
• NEVER
• Client in transaction: throws exception
• Client without transaction: without a transaction
• SUPPORTS
• Client in transaction: uses transaction
• Client without transaction: without a transaction
• NOT_SUPPORTED
• Client in transaction: without a transaction
• Client without transaction: without a transaction
55 JEE - Enterprise Java Beans
56 Introduction to Java Platform, Enterprise Edition

More Related Content

What's hot (20)

Java persistence api 2.1
Java persistence api 2.1Java persistence api 2.1
Java persistence api 2.1
 
Servlet and servlet life cycle
Servlet and servlet life cycleServlet and servlet life cycle
Servlet and servlet life cycle
 
Jdbc Ppt
Jdbc PptJdbc Ppt
Jdbc Ppt
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
java 8 new features
java 8 new features java 8 new features
java 8 new features
 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
Spring Boot in Action
Spring Boot in Action Spring Boot in Action
Spring Boot in Action
 
Optional in Java 8
Optional in Java 8Optional in Java 8
Optional in Java 8
 
JPA and Hibernate
JPA and HibernateJPA and Hibernate
JPA and Hibernate
 
Java exception handling ppt
Java exception handling pptJava exception handling ppt
Java exception handling ppt
 
Java Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | EdurekaJava Design Patterns Tutorial | Edureka
Java Design Patterns Tutorial | Edureka
 
Spring & hibernate
Spring & hibernateSpring & hibernate
Spring & hibernate
 
Session bean
Session beanSession bean
Session bean
 
Java Tokens
Java  TokensJava  Tokens
Java Tokens
 
Inheritance
InheritanceInheritance
Inheritance
 
Intro to functional programming
Intro to functional programmingIntro to functional programming
Intro to functional programming
 
Hibernate ppt
Hibernate pptHibernate ppt
Hibernate ppt
 
Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)Remote Method Invocation (Java RMI)
Remote Method Invocation (Java RMI)
 
Exception handling in .net
Exception handling in .netException handling in .net
Exception handling in .net
 

Viewers also liked

Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in javaAcp Jamod
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEEFahad Golra
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Fahad Golra
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web SocketsFahad Golra
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: ServletsFahad Golra
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Fahad Golra
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RSFahad Golra
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionKelum Senanayake
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)Fahad Golra
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session ManagementFahad Golra
 
Entreprise Java Beans (EJB)
Entreprise Java Beans (EJB)Entreprise Java Beans (EJB)
Entreprise Java Beans (EJB)Heithem Abbes
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, mavenFahad Golra
 
Tutorial 4 - Basics of Digital Photography
Tutorial 4 - Basics of Digital PhotographyTutorial 4 - Basics of Digital Photography
Tutorial 4 - Basics of Digital PhotographyFahad Golra
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkBill Lyons
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4phanleson
 

Viewers also liked (20)

EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
Entity beans in java
Entity beans in javaEntity beans in java
Entity beans in java
 
Lecture 1: Introduction to JEE
Lecture 1:  Introduction to JEELecture 1:  Introduction to JEE
Lecture 1: Introduction to JEE
 
Java bean
Java beanJava bean
Java bean
 
Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2Lecture 9 - Java Persistence, JPA 2
Lecture 9 - Java Persistence, JPA 2
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
Lecture 6 Web Sockets
Lecture 6   Web SocketsLecture 6   Web Sockets
Lecture 6 Web Sockets
 
Lecture 2: Servlets
Lecture 2:  ServletsLecture 2:  Servlets
Lecture 2: Servlets
 
Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)Lecture 10 - Java Server Faces (JSF)
Lecture 10 - Java Server Faces (JSF)
 
Lecture 7 Web Services JAX-WS & JAX-RS
Lecture 7   Web Services JAX-WS & JAX-RSLecture 7   Web Services JAX-WS & JAX-RS
Lecture 7 Web Services JAX-WS & JAX-RS
 
EJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another IntroductionEJB 3.0 - Yet Another Introduction
EJB 3.0 - Yet Another Introduction
 
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)Lecture 4:  JavaServer Pages (JSP) & Expression Language (EL)
Lecture 4: JavaServer Pages (JSP) & Expression Language (EL)
 
Lecture 3: Servlets - Session Management
Lecture 3:  Servlets - Session ManagementLecture 3:  Servlets - Session Management
Lecture 3: Servlets - Session Management
 
Entreprise Java Beans (EJB)
Entreprise Java Beans (EJB)Entreprise Java Beans (EJB)
Entreprise Java Beans (EJB)
 
Ejb3 Presentation
Ejb3 PresentationEjb3 Presentation
Ejb3 Presentation
 
Bean Intro
Bean IntroBean Intro
Bean Intro
 
Lecture 5 JSTL, custom tags, maven
Lecture 5   JSTL, custom tags, mavenLecture 5   JSTL, custom tags, maven
Lecture 5 JSTL, custom tags, maven
 
Tutorial 4 - Basics of Digital Photography
Tutorial 4 - Basics of Digital PhotographyTutorial 4 - Basics of Digital Photography
Tutorial 4 - Basics of Digital Photography
 
EJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLinkEJB 3.0 Java Persistence with Oracle TopLink
EJB 3.0 Java Persistence with Oracle TopLink
 
Session 4 Tp4
Session 4 Tp4Session 4 Tp4
Session 4 Tp4
 

Similar to Lecture 8 Enterprise Java Beans (EJB)

The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologySimon Ritter
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Rohit Kelapure
 
Java EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConJava EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConLudovic Champenois
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7WASdev Community
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7Kevin Sutter
 
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
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabadrevanthonline
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 javatwo2011
 
What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?Sanjeeb Sahoo
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)Montreal JUG
 
Overview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGOverview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGMarakana Inc.
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)Kevin Sutter
 
Contexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformContexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformBozhidar Bozhanov
 
Java ee 8 + security overview
Java ee 8 + security overviewJava ee 8 + security overview
Java ee 8 + security overviewRudy De Busscher
 
Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Arun Gupta
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010Arun Gupta
 
OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6glassfish
 
Java Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewJava Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewEugene Bogaart
 

Similar to Lecture 8 Enterprise Java Beans (EJB) (20)

The Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans TechnologyThe Latest in Enterprise JavaBeans Technology
The Latest in Enterprise JavaBeans Technology
 
Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010Contextual Dependency Injection for Apachecon 2010
Contextual Dependency Injection for Apachecon 2010
 
Java EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseConJava EE 6, Eclipse @ EclipseCon
Java EE 6, Eclipse @ EclipseCon
 
AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7AAI-1713 Introduction to Java EE 7
AAI-1713 Introduction to Java EE 7
 
AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7AAI 1713-Introduction to Java EE 7
AAI 1713-Introduction to Java EE 7
 
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
 
Java online training from hyderabad
Java online training from hyderabadJava online training from hyderabad
Java online training from hyderabad
 
Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望 Java EE 與 雲端運算的展望
Java EE 與 雲端運算的展望
 
What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?What's New in Enterprise JavaBean Technology ?
What's New in Enterprise JavaBean Technology ?
 
Virtual classroom
Virtual classroomVirtual classroom
Virtual classroom
 
EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)EJB et WS (Montreal JUG - 12 mai 2011)
EJB et WS (Montreal JUG - 12 mai 2011)
 
Overview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUGOverview of Java EE 6 by Roberto Chinnici at SFJUG
Overview of Java EE 6 by Roberto Chinnici at SFJUG
 
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)InterConnect 2016 Java EE 7 Overview (PEJ-5296)
InterConnect 2016 Java EE 7 Overview (PEJ-5296)
 
Contexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platformContexts and Dependency Injection for the JavaEE platform
Contexts and Dependency Injection for the JavaEE platform
 
Java ee 8 + security overview
Java ee 8 + security overviewJava ee 8 + security overview
Java ee 8 + security overview
 
Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014Java EE 7 Soup to Nuts at JavaOne 2014
Java EE 7 Soup to Nuts at JavaOne 2014
 
Advance java1.1
Advance java1.1Advance java1.1
Advance java1.1
 
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
S314168 - What's New in Enterprise Java Bean Technology @ JavaOne Brazil 2010
 
OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6OTN Developer Days - Java EE 6
OTN Developer Days - Java EE 6
 
Java Enterprise Edition 6 Overview
Java Enterprise Edition 6 OverviewJava Enterprise Edition 6 Overview
Java Enterprise Edition 6 Overview
 

More from Fahad Golra

Seance 4- Programmation en langage C
Seance 4- Programmation en langage CSeance 4- Programmation en langage C
Seance 4- Programmation en langage CFahad Golra
 
Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Fahad Golra
 
Seance 2 - Programmation en langage C
Seance 2 - Programmation en langage CSeance 2 - Programmation en langage C
Seance 2 - Programmation en langage CFahad Golra
 
Seance 1 - Programmation en langage C
Seance 1 - Programmation en langage CSeance 1 - Programmation en langage C
Seance 1 - Programmation en langage CFahad Golra
 
Tutorial 3 - Basics of Digital Photography
Tutorial 3 - Basics of Digital PhotographyTutorial 3 - Basics of Digital Photography
Tutorial 3 - Basics of Digital PhotographyFahad Golra
 
Tutorial 2 - Basics of Digital Photography
Tutorial 2 - Basics of Digital PhotographyTutorial 2 - Basics of Digital Photography
Tutorial 2 - Basics of Digital PhotographyFahad Golra
 
Tutorial 1 - Basics of Digital Photography
Tutorial 1 - Basics of Digital PhotographyTutorial 1 - Basics of Digital Photography
Tutorial 1 - Basics of Digital PhotographyFahad Golra
 
Deviation Detection in Process Enactment
Deviation Detection in Process EnactmentDeviation Detection in Process Enactment
Deviation Detection in Process EnactmentFahad Golra
 
Meta l metacase tools & possibilities
Meta l metacase tools & possibilitiesMeta l metacase tools & possibilities
Meta l metacase tools & possibilitiesFahad Golra
 

More from Fahad Golra (9)

Seance 4- Programmation en langage C
Seance 4- Programmation en langage CSeance 4- Programmation en langage C
Seance 4- Programmation en langage C
 
Seance 3- Programmation en langage C
Seance 3- Programmation en langage C Seance 3- Programmation en langage C
Seance 3- Programmation en langage C
 
Seance 2 - Programmation en langage C
Seance 2 - Programmation en langage CSeance 2 - Programmation en langage C
Seance 2 - Programmation en langage C
 
Seance 1 - Programmation en langage C
Seance 1 - Programmation en langage CSeance 1 - Programmation en langage C
Seance 1 - Programmation en langage C
 
Tutorial 3 - Basics of Digital Photography
Tutorial 3 - Basics of Digital PhotographyTutorial 3 - Basics of Digital Photography
Tutorial 3 - Basics of Digital Photography
 
Tutorial 2 - Basics of Digital Photography
Tutorial 2 - Basics of Digital PhotographyTutorial 2 - Basics of Digital Photography
Tutorial 2 - Basics of Digital Photography
 
Tutorial 1 - Basics of Digital Photography
Tutorial 1 - Basics of Digital PhotographyTutorial 1 - Basics of Digital Photography
Tutorial 1 - Basics of Digital Photography
 
Deviation Detection in Process Enactment
Deviation Detection in Process EnactmentDeviation Detection in Process Enactment
Deviation Detection in Process Enactment
 
Meta l metacase tools & possibilities
Meta l metacase tools & possibilitiesMeta l metacase tools & possibilities
Meta l metacase tools & possibilities
 

Recently uploaded

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityNeo4j
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....kzayra69
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfIdiosysTechnologies1
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmSujith Sukumaran
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentationvaddepallysandeep122
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationBradBedford3
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...Technogeeks
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 

Recently uploaded (20)

EY_Graph Database Powered Sustainability
EY_Graph Database Powered SustainabilityEY_Graph Database Powered Sustainability
EY_Graph Database Powered Sustainability
 
What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....What are the key points to focus on before starting to learn ETL Development....
What are the key points to focus on before starting to learn ETL Development....
 
Best Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdfBest Web Development Agency- Idiosys USA.pdf
Best Web Development Agency- Idiosys USA.pdf
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Intelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalmIntelligent Home Wi-Fi Solutions | ThinkPalm
Intelligent Home Wi-Fi Solutions | ThinkPalm
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
PREDICTING RIVER WATER QUALITY ppt presentation
PREDICTING  RIVER  WATER QUALITY  ppt presentationPREDICTING  RIVER  WATER QUALITY  ppt presentation
PREDICTING RIVER WATER QUALITY ppt presentation
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
How to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion ApplicationHow to submit a standout Adobe Champion Application
How to submit a standout Adobe Champion Application
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...What is Advanced Excel and what are some best practices for designing and cre...
What is Advanced Excel and what are some best practices for designing and cre...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 

Lecture 8 Enterprise Java Beans (EJB)

  • 1. Enterprise JavaBeans (EJB 3.x) Fahad R. Golra ECE Paris Ecole d'Ingénieurs - FRANCE
  • 2. Lecture 8 - Enterprise Java Beans (EJB) • Introduction to EJBs • Types of EJBs • Session Beans • Message Driven Beans • Transaction Management 2 JEE - Enterprise Java Beans
  • 3. 3 Layers of Information System 3 JEE - Enterprise Java Beans presentation layer application logic layer resource management layer Client informationsystem EJB JSP JSF Servlets JPA Database
  • 4. Java EE Server • The runtime portion of a Java EE product. A Java EE server provides EJB and web containers. 4 JEE - Enterprise Java Beans
  • 5. When to use EJB? • If the application needs • to be scalable • a transactional context • diversity of clients 5 JEE - Enterprise Java Beans
  • 6. Why to use EJBs • Encapsulate business logic • multi-tier architecture • Remote access • apps on different servers can access them • Simplicity • simpler than other remote object systems • Broad vendor support • JBoss, Oracle AS, WebLogic, WepSphere • Scalability • support for clustering, load-balancing and failover 6 JEE - Enterprise Java Beans
  • 7. Why EJB 3.x • Network connections between the clients and the EJBs • Naming services (JNDI) • Transactions • Persistence and the management of DB pool of connections • Distribution • Security • Management of component’s life cycle 7 JEE - Enterprise Java Beans
  • 8. Types of EJB 8 EJB Message-Driven Session Entity (pruned) [JPA] StatelessStateful Container Managed Persistence Bean Managed Persistence Singleton Bean Type Annotation Session Bean Performs a task for a client; optionally, may implement a web service Message- driven Bean Acts as a listener for a particular messaging type, such as the Java Message Service API
  • 9. Stateless Session Beans • Used when • The bean's state has no data for a specific client. • In a single method invocation, the bean performs a generic task for all clients. For example, you might use a stateless session bean to send an email that confirms an online order. • The bean implements a web service. 9 JEE - Enterprise Java Beans
  • 10. Stateless Session Beans 10 JEE - Enterprise Java Beans Java EE Server EJB Container Stateless Bean Pool Bean Instance Bean Instance Bean Instance client Random A random bean instance is selected from the pool
  • 11. Stateful Session Beans • Used when the following conditions are true • The bean's state represents the interaction between the bean and a specific client. • The bean needs to hold information about the client across method invocations. • The bean mediates between the client and the other components of the application, presenting a simplified view to the client. • Behind the scenes, the bean manages the work flow of several enterprise beans. 11 JEE - Enterprise Java Beans
  • 12. Stateful Session Beans 12 JEE - Enterprise Java Beans Java EE Server EJB Container Bean Instance Bean Instance Bean Instance client C client B client A One bean instance per client
  • 13. Singleton Session Beans • They are used when • State needs to be shared across the application. • A single enterprise bean needs to be accessed by multiple threads concurrently. • The application needs an enterprise bean to perform tasks upon application startup and shutdown. • The bean implements a web service. 13 JEE - Enterprise Java Beans
  • 14. Singleton Session Beans 14 JEE - Enterprise Java Beans Java EE Server EJB Container Bean Instance client C client B client A One bean instance per application server instance
  • 15. Category Related Annotations 15 JEE - Enterprise Java Beans Bean Type Annotation Session Bean @Stateless @Stateful @Singleton Message-driven Bean @MessageDriven JPA Entities @Entity* @EntityManager*
  • 16. Contents of EJB • Enterprise bean class: • business methods of the enterprise bean • any lifecycle callback methods. • Business interfaces: • define the business methods • not required if the enterprise bean exposes a local, no-interface view • Helper classes: • other classes needed by the enterprise bean class, such as exception and utility classes. 16 JEE - Enterprise Java Beans
  • 17. Remote & Local Access 17 JEE - Enterprise Java Beans presentation layer application logic layer resource management layer Client informationsystem EJB A JSP JSF Servlets JPA DatabaseJava EE Server EJB B Desktop app Legend: Local client Remote client
  • 18. Access Mode Annotations 18 JEE - Enterprise Java Beans Bean Type Annotation Session Bean @Local @Remote @LocalBean* @WebService Message-driven Bean @WebService JPA Entities N/A
  • 19. Remote & Local Access • Whether to allow local or remote access depends on the following factors. • Tight or loose couple of related beans • Type of client: web components on the same server or application clients, etc. • Component Distribution: A scalable server on multiple servers • Performance: Remote calls may be slower than local calls. Distributed computing on different servers for performance. 19 JEE - Enterprise Java Beans
  • 20. EJB Business Interfaces • Local Interface @Local public interface MyStatelessBeanLocal { String sayHello(String name); } • Remote Interface @Remote public interface MyStatelessBeanRemote { String sayHello(String name); } 20
  • 21. Stateless Session Beans • Each invocation of a stateless business method is independent from previous invocations • Because stateless session beans are "stateless" they tend to process requests faster and use less resources • All instances are equivalent – the EJB container can assign a pooled stateless bean instance to any client, improving scalability 21 JEE - Enterprise Java Beans
  • 22. Stateless session bean lifecycle 22 JEE - Enterprise Java Beans NON EXISTENT READY • Create new bean instance • DI on bean, if any • @PostConstruct, if any • @PreDestroy, if any Client DI or JNDI lookup Instances are removed automatically from the pool by the container
  • 23. Example Hello Bean (Stateless) @Stateless @Local(MyStatelessBeanLocal.class) @Remote(MyStatelessBeanRemote.class) public class MyStatelessBean implements MyStatelessBeanRemote, MyStatelessBeanLocal { public MyStatelessBean() { // TODO Auto-generated constructor stub } @Override public String sayHello(String name) { return "hello, " + name; } } 23 JEE - Enterprise Java Beans
  • 24. JNDI Lookup • Clients find the bean via JNDI • Client Java code doesn’t even know the machine on which the bean resides • Clients use the bean like a normal POJO • But arguments and return values are sent across network ︎ So, custom classes should be Serializable InitialContext context = new InitialContext(); InterfaceName bean =(InterfaceName)context.lookup("JNDI- Name"); • jndi.properties • ︎Text file in classpath; gives remote URL and other info 24 JEE - Enterprise Java Beans
  • 25. Accessing Local EJB • Dependency Injection @EJB MyStatelessBeanLocal myDIBeanLocal; • JNDI Lookup Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); Context context = new InitialContext(jndiProperties); MyStatelessBeanLocal myJNDIBeanLocal = (MyStatelessBeanLocal) context.lookup(“java:module/MyStatelessBean! com.ece.jee.MyStatelessBeanLocal”); • Clients do not use the new operator to obtain a new instance 25 JEE - Enterprise Java Beans
  • 26. Accessing Remote EJB • Dependency Injection @EJB MyStatelessBeanRemote myDIBeanRemote; • JNDI Lookup Hashtable jndiProperties = new Hashtable(); jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming"); Context context = new InitialContext(jndiProperties); MyStatelessBeanLocal myJNDIBeanLocal = (MyStatelessBeanLocal) context.lookup(“java:module/MyStatelessBean! com.ece.jee.MyStatelessBeanLocal”); • Clients do not use the new operator to obtain a new instance 26 JEE - Enterprise Java Beans
  • 27. Portable JNDI Syntax • java:global • JNDI namespace for remote EJBs java:global[/application name]/module name /enterprise bean name[/ interface name ] • java:module • JNDI namespace for local EJBs within the same module. java:module/enterprise bean name/[interface name] • java:app • JNDI namespace is used to look up local EJBs packaged within the same application. java:app[/module name]/enterprise bean name [/interface name] 27 JEE - Enterprise Java Beans
  • 28. Stateful Session Beans • POJOs • Instance of the Bean relates to a specific client (in memory while he/she is connected) • Expires in case of inactivity (similar to session in Servlet/Jsp) • Ordinary Java classes; no special interfaces or parent classes. 
 • Local or remote access • Can be accessed either on local app server or remote app server • Session Expiry • ︎ The Session expires after the method annotated with @Remove is executed • Session can also expire in case of a time-out 28 JEE - Enterprise Java Beans
  • 29. Stateful session bean lifecycle 29 JEE - Enterprise Java Beans NON EXISTENT READY PASSIVE • Create new bean instance • DI on bean, if any • @PostConstruct, if any Before instance passivation • @PrePassivate, if any After instance activation • @PostActivate, if any • @Remove* • @PreDestroy, if any Client DI or JNDI lookup * Method called by the client code, other methods are called by container
  • 30. Callback method annotations @PostConstruct public void initialize() { ... at Bean’s initialization ... } @PreDestroy • public void destroy() { ... destruction of Bean ... } @PrePassivate //only for Stateful beans public void beforeSwap() { ... to do before Bean is passivated ... } @PostActivate //only for Stateful beans public void afterSwap() { ... to do after Bean is activated ... } 30 JEE - Enterprise Java Beans
  • 31. @Remove • Container does not manage a pool for Stateful EJBs • If the instance is not removed it stays in the memory • A timeout from the server destroys the bean instance from READ or PASSIVE state • A method with @Remove annotation is used to manage the destruction of instance @Remove public void destroy(){ } 31 JEE - Enterprise Java Beans
  • 32. Singleton Session Beans • Only one instance is created per bean • All clients use the same instance • @Startup loads it, when server starts • Concurrency can be managed by two ways • Container Managed Concurrency • Bean Managed Concurrency • Bean Concurrency @ConcurrencyManagement(ConcurrencyManagementType.BEAN) public class MySingleton { Use synchronised, volatile, etc. 32 JEE - Enterprise Java Beans
  • 33. Container Managed Concurrency • Uses READ and WRITE locks • WRITE lock: No other READ or WRITE method can be executed concurrently • READ lock: Only READ lock methods can be executed concurrently • Default concurrency management is Container • Default lock for all methods is WRITE lock 33 JEE - Enterprise Java Beans
  • 34. Container Managed Concurrency @ConcurrencyManagement(ConcurrencyManagementType.CONTAINER) public class MySingleton { @Lock(LockType.WRITE) public void myMethod1() {} @Lock(LockType.READ) public void myMethod2() {} } 34 JEE - Enterprise Java Beans
  • 35. Singleton session bean lifecycle 35 JEE - Enterprise Java Beans NON EXISTENT READY • @Startup, create new bean instance • DI on bean, if any • @PostConstruct, if any • @PreDestroy, if any EJB Container
  • 36. EJB and Web Services • A client can access a JavaEE application through • JAX-WS web service • Business methods of EJB @Stateless @WebService public class HelloServiceBean { private final String message = "Hello, "; public void HelloServiceBean() { } @WebMethod public String sayHello(String name) { return message + name + "."; } } 36 JEE - Enterprise Java Beans
  • 37. Message-Driven Vs Stateless Beans • Resemblances • Retain no data or conversational state for a specific client. • All instances are equivalent. EJB container can • assign a message to any message-driven bean instance • pool these instances to allow streams of messages to be processed concurrently • A single message-driven bean can process messages from multiple clients. 37 JEE - Enterprise Java Beans
  • 38. Message-Driven Vs Stateless Beans • Differences • clients do not access message-driven beans through interfaces • contain some state across the handling of client messages, • JMS API connection, an open database connection, etc. • client access through JMS • by sending messages to the message destination for which the message-driven bean class is the MessageListener. 38 JEE - Enterprise Java Beans
  • 39. Message Driven Bean • They have the following characteristics • 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. 39 JEE - Enterprise Java Beans
  • 40. Message-driven bean lifecycle 40 JEE - Enterprise Java Beans NON EXISTENT READY • DI on bean, if any • Create new bean instance • @PostConstruct, if any • @PreDestroy, if any • Destroy the bean instance • onMessage
  • 41. Message-driven bean • JMS (java.sun.com/jms) • Two mothers of communication • Queue : Thread of discussion (one consumer) • Topic : Topic of discussion (diffusion) • ConnectionFactory : Factory of connections towards queue/topic • Connection : connection towards queue/topic • Session : • Creation of an sender and of a receiver ︎ • Can be transactional 41 JEE - Enterprise Java Beans
  • 42. Message Driven Bean @MessageDriven(activationConfig ={ @ActivationConfigProperty( propertyName = "destination", propertyValue = "topic_ece"), @ActivationConfigProperty( propertyName = "destinationType", propertyValue = "javax.jms.Topic")}) public class Mdb implements MessageListener { public void onMessage(Message inMessage) { System.out.println(((TextMessage)msg).getText()); } } 42
  • 43. Message Driven Bean (Sender) @Resource(name="rigolo", mappedName="topic_rigolo") Topic topic;
 @Resource(name="factory", mappedName="JTCF") TopicConnectionFactory factory;
 TopicSession session;
 TopicPublisher sender; public void publish(String value) {
 TopicConnection tc = factory.createTopicConnection(); session = tc.createTopicSession(false,Session.AUTO_ACKNOWLEDGE); sender = session.createPublisher(topic); TextMessage msg = session.createTextMessage(); msg.setText("MDB: " + value); sender.publish(msg); } 43
  • 44. Transaction Management • Business Transaction • Interaction in real world • Usually between enterprise & person or between enterprises • Information processing that is divided into individual, indivisible operations, called transactions • Performs function on (shared) database 44 JEE - Enterprise Java Beans
  • 45. The ACID Properties • A set of properties that guarantee that transactions are processed reliably • Atomicity • Consistency • Isolation • Durability 45 JEE - Enterprise Java Beans
  • 46. Atomicity • All (commit) or nothing (abort) • "all or nothing": if one part of the transaction fails, the entire transaction fails • Example: transfer money between two bank accounts • Must handle situations including power failures, errors, and crashes 46 JEE - Enterprise Java Beans
  • 47. Consistency • Each transaction takes valid states to valid states: • Satisfy integrity constraints, triggers • Sometimes the only notion of “valid” state is “a state that could have been produced by executing a sequence of transactions 47 JEE - Enterprise Java Beans
  • 48. Isolation • Each transaction behaves as if it were executed in isolation at some instant in time • AKA Serializability • Ensures that the concurrent execution of transactions results in a system state that would be obtained if transactions were executed serially • Consistency + Isolation implies the data remains consistent even when multiple transaction programs execute concurrently 48 JEE - Enterprise Java Beans
  • 49. Durability • The effect of a committed transaction will not be lost • Even in the event of power loss, crashes, or errors • So data must be on stable storage before commit • Usually done with a log (or journal) that must be forced before commit and used in case of crash recovery 49 JEE - Enterprise Java Beans
  • 50. Transactions • There are two types of transactions • Local Transactions • They span only on a single resource • Global Transactions (JTA Transactions) • They span on multiple resources • Default transaction in Java EE • Two management styles • Container managed transactions (default) • Bean managed transactions 50 JEE - Enterprise Java Beans
  • 51. Management Mode Annotations 51 JEE - Enterprise Java Beans Bean Type Annotation Transactions @TransactionManagement (CONTAINER) @TransactionManagement (BEAN) Security @RunAs() @RolesAllowed
  • 52. Bean Managed Transactions • Manually manage the transaction @TransactionManagement(TransactionManagementType.BEAN) public class MyBean { @Resource private UserTransaction tx; public void myMethod() { try { tx.begin(); methodcall1(); methodcall2(); methodcall3(); tx.commit(); } catch (Exception e) { e.printStackTrace();} } } 52 JEE - Enterprise Java Beans
  • 53. Contrainer Managed Transactions • The start and stop of transactions is managed by container @TransactionManagement(TransactionManagementType.CONTAINER) public class MyTester { @TransactionAttribute(TransactionAttributeType.MANDATORY) public void myMethod() { methodcall1(); methodcall2(); methodcall3(); } } 53 JEE - Enterprise Java Beans
  • 54. Transaction Attributes • REQUIRED • Client in transaction: uses transaction • Client without transaction: creates new transaction • REQUIRES_NEW • Client in transaction: creates new transaction • Client without transaction: creates new transaction • MANDATORY • Client in transaction: uses transaction • Client without transaction: throws exception 54 JEE - Enterprise Java Beans
  • 55. Transaction Attributes • NEVER • Client in transaction: throws exception • Client without transaction: without a transaction • SUPPORTS • Client in transaction: uses transaction • Client without transaction: without a transaction • NOT_SUPPORTED • Client in transaction: without a transaction • Client without transaction: without a transaction 55 JEE - Enterprise Java Beans
  • 56. 56 Introduction to Java Platform, Enterprise Edition