File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes How to use these EJB's? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "How to use these EJB Watch "How to use these EJB New topic

How to use these EJB's?

J.H.B. Oosterlaar
Ranch Hand

Joined: Sep 12, 2002
Posts: 41
The situation: We have a Servlet that receives HTTP requests. These requests need to be stored in a database. To prevent the Servlet from waiting on the write action, we want the writing to be a asynchronic process.
The (possible) solution: We use a EJB container which contains beans. A message-driven-bean is used to 'transfer' the HTTP request data (the Servlet calls the message-driven-bean). The message-driven-bean passes the data (probably a bean also), to the buffering entity bean. After a buffering limit has been reached, the buffer is written to the database.
QUESTION 1: How should we approach this enitity bean? Just a bean that has its own buffer (Vector for instance)? Or do we need to define the entity bean by it's unique element. The entity bean represents an element from the buffer, so there is no actual buffer. We prefer the first option, since there is some business logic involved on the database storage (testing, etc.). The buffer is filled, when the limit has been reached, it instantiates a Thread that does the actual storing, so that the buffering itself can continue.
Continue: When the Servlet is first instantiated, it needs to know a maximum value from the database. We don't want to make another database connection around the EJB container, so we want to do this through the EJB container.
QUESTION 2: We need an EJB that retrieves the needed value from the database and can be called by the Servlet, so that this Servlet can get the value. This EJB does not need to exsist for a long period. It only has to be instantiated when the Servlet calls it. What kind of bean do we have to use? We really want it to be inside the EJB container.
Thanks in advance!
Jeroen Oosterlaar
P.S. Is this a good way of solving the storage? Or would the use of Thread in the Servlet container be sufficient?
Sudd Ghosh
Ranch Hand

Joined: Oct 23, 2002
Posts: 187
I haven't worked a lot on these, but wondering, regarding your Q1, "buffering entity bean", why not use a CMP bean and leave the buffering to the database ? You can always configure the DB to have any kind of buffering you want.

I agree. Here's the link:
subject: How to use these EJB's?
It's not a secret anymore!