• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Partial Commit Entity EJB

 
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Let's say I have an EJB session bean that runs for 10 minutes. During this time it tracks its progress by updating a percentage complete field for a particular row in a Process database table, via an EJB entity bean ProcessBean.

Problem is this: Commits for the Process table updates do not take place until after the 10 minutes has elapsed. In other words the user sees 0%, then after 10 minutes sees 100%. Is there a simple way to read the process data before the larger process has finished?

I have a few ideas but none that really sit well with me. I could force incremental commits of the entire transaction, but that would interfere with the transactional stability of the larger process. I could convert the CMP bean into BMP bean, although that seems like a waste of time. Finally, I could use a static object cache, but that seems like a bad idea since I'm essentially replicating the persistence cache.
 
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can a transaction last for 10 minutes?
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Easily? It's spawned via an asynchronous MDB. I'll leave it up to your imagination to determine why you might need a long-running process.
[ May 29, 2008: Message edited by: Scott Selikoff ]
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Indeed, that's my real question: why would a transaction last that long. I would question any EJB transaction which lasts for more than 30 seconds. If it does, then a redesign is probably needed.
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What about using the "RequiresNew" transaction attribute on the method of the ProcessBean that updates the row? Your outer transaction would be suspended, a new transaction would be created, the row updated, the new transaction complete and commit the change, and your outer transaction would resume. This should make changes to that row visible outside the large outer transaction.
 
Scott Selikoff
author
Posts: 4335
39
jQuery Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Roger Chung-Wee:
why would a transaction last that long. I would question any EJB transaction which lasts for more than 30 seconds. If it does, then a redesign is probably needed.



Again I'll leave it to your imagination.

For RequiresNew, that might work although my worry is that each time an update is performed a substantional overhead of suspending/resuming the main transaction might be incurred.

I think for now I'm going with a static object cache. It's easy enough to implement.
 
Would you turn that thing down? I'm controlling a mind here! Look ... look at the tiny ad ...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic