Two Laptop Bag
The moose likes EJB and other Java EE Technologies and the fly likes Call Back from EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "Call Back from EJB" Watch "Call Back from EJB" New topic

Call Back from EJB

Prem Kumar

Joined: Jan 29, 2006
Posts: 14
Hi Friends,

I am wondering how call back happens in EJB.
I created an interface called CallBack.This extends Remote.
This contains a method update(String msg).

CallBack extends Remote {
void update(String msg) throws RemoteException;

Then to my ejb i pass this interface as shown below.
public void register(CallBack callback) {
try {
if(callback!=null) {
callback.update("Msg from Server");
}catch(RemoteException e){
I created a client which implements the CallBack interface and i called
the ejb's register method.Surprisingly i got a message from the server.
How does this work. Normally in RMI for the call back to work the client
should also expose itself as a RMI Server.This is usually done by
UnicastRemoteObject.exportObject(client);After this you use rmic to generate the stub and skeleton classes. For the EJB case i didnt export the client with exportObject nor i generated any stub and skeleton. How was the ejb able to call back the client in this scenario.Sorry for the long mail


Have a Great Day!
Roger Chung-Wee
Ranch Hand

Joined: Sep 29, 2002
Posts: 1683
You have described a regular EJB method. But callbacks are different because they are tied to the EJB's life cycle. Callbacks are invoked on the bean's instance by the container, eg setSessionContext of a session bean during the transition from its "does not exist" state to "method ready" state. Apart from a few exceptions such as ejbLoad and ejbStore of BMP entity beans, callbacks are never invoked by a bean or client.

SCJP 1.4, SCWCD 1.3, SCBCD 1.3
I agree. Here's the link:
subject: Call Back from EJB
It's not a secret anymore!