This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Callback Methods in EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Callback Methods in EJB" Watch "Callback Methods in EJB" New topic

Callback Methods in EJB

Anganna Venkatesh

Joined: Dec 07, 2005
Posts: 1
I have a question.
What are callback methods and why are they named so?

Puneet Vashisht
Ranch Hand

Joined: Jul 30, 2005
Posts: 44
I have a question.
What are callback methods and why are they named so?


If u are talking of container callback methods, then these are the methods only container has the privelege to call, like ur ejbcreate().
As to y they are called callback methods, i dont even have a hint. The whole nomenclature used wid EJB is so confusing.
Ranch Hand

Joined: Aug 18, 2005
Posts: 372
Callback methods are methods called by the container on the EJB to notify the EJB of important events in it's lifecycle such as creation, activation, passivation, removal etc. They are given a different name to distinguish them from normal business methods which are also actually invoked by the container on the EJB.

If you are from a WCD background, this might help - you can consider them to be similar to say, the contextInitialized(ServletContextEvent se) and contextDestroyed(ServletContextEvent se) methods of ServletContextListener. These are methods called by the web container on the listener class to notify the class of context-related events
Sankar Subbiramaniam
Ranch Hand

Joined: Oct 03, 2000
Posts: 116
In Client-Server applications, normally it is the client which (initiates the) call to the server for services (Client ---> Server). However there are situations where the server wants to notify the client of some event (eg: ejb lifecycle status change). In these situation the server initiates a call back to the client. (Client <----- Server)
Hence they are called callback methods.

Note: In EJB, a deployed bean is a client of the container.

Hope this helps.
Devender Thareja
Ranch Hand

Joined: Jul 14, 2005
Posts: 187
Originally posted by Sankar Subbiramaniam:

Note: In EJB, a deployed bean is a client of the container.

Hope this helps.

It's confusing. Sankar, I don't think it's right to say that bean is a client to container.

This is how I understand it so far: A bean is an object inside container. However, whatever business methods you call on a bean, you are really calling on a subclass of bean you wrote. The container adds more meat to the class you write and extends it. So in the grand scheme of things, container is controlling everything but in between at appropriate times, it calls methods which you wrote. This is already agreed upon in spec that what services container will provide and at what time and situation it will callback the bean methods. The agreed upon methods are container callback methods. You can also add methods which are not defined in the spec or in other words are not container callback methods but they will never be called by container and should be called from container callback methods you write, otherwise they will be use-less.
The container callback name seems to appropriate in this situation. Do you have more appropriate name in mind?

Devender Thareja
I agree. Here's the link:
subject: Callback Methods in EJB
It's not a secret anymore!