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 entity bean writes many records 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 "entity bean writes many records" Watch "entity bean writes many records" New topic

entity bean writes many records

Gayatri Sinha
Ranch Hand

Joined: Feb 13, 2006
Posts: 34

I am trying to write into the database many records (say >1000) using entity beans.
The problem is when the user hits the submit button for this processing, he has to wait for a long time till the long process completes and is forwarded to the next page on success.
Sometimes, the user may think that the page is doing nothing and hit the submit button twice due to the delay.

Is there a way, that I cud put this process (writing 1000 records) in a queue and return to the next page so the user sees the next page soon and the writing to database takes place in the back?

Andreas Schaefer
Ranch Hand

Joined: Feb 13, 2006
Posts: 63
You just answered your own question. Just send a JMS message and use a MDB to put the records into the DB. But be aware that the client does not know if the operation succeeded or not.
Reid M. Pinchback
Ranch Hand

Joined: Jan 25, 2002
Posts: 775
Given that you posted this in the EJB forum, presumably these database interactions are somehow implemented in EJB, e.g. entity beans. If so, another thing to take a look at are the vendor-specific deployment descriptor options that control how your database changes are actually processed during and at the end of the transaction. Sometimes you can get a very significant speedup by ensuring that all the writes happen just on the transaction commit. Particularly in WebLogic and I believe also in the most recent JBoss 3.2.x and 4.0.x releases, you can see very big differences in CMP performance because the container can sometimes switch to using SQL batching.

The JMS approach works ok too, but only if you aren't expecting to forward the user to a page that reflects the committed results. Obviously those won't always be available if the changes are off processing in some other thread of execution.

Reid - SCJP2 (April 2002)
I agree. Here's the link:
subject: entity bean writes many records
It's not a secret anymore!