• Post Reply Bookmark Topic Watch Topic
  • New Topic

Optimistic Locking Performance Advice Needed

 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there,

We have an EJB method that roughly does the following; we have a number of buckets that may or may not be full. If one or more are not full we want it to find the one with the most space available and add the item there. Our main problem here is that this method can be called upwards of 1000 times per second and we're now looking for an efficient way to solve the concurrency issue of two different calls both thinking bucket X has space left even though one of the two calls will fill it up :

THREAD 1 : findEmptyBucket() returns BUCKET1 (1 SPOT LEFT)
THREAD 2 : findEmptyBucket() returns BUCKET1 (1 SPOT LEFT)
THREAD 1 : addItemToBucket(BUCKET1) <- FULL NOW
THREAD 2 : addItemToBucket(BUCKET1) <- WRONG

I think the "EJB3" approach is basically (pseudoish) :



This seems horribly inefficient for a call that is almost guaranteed to require dozens of retries during peak hours. Is there any way to optimize this in such a way that we don't have to use optimistic locking? We're trying to solve this without using vendor specific solutions but EJB3 seems to lack the necessary functionality. Suggestions definitely welcome, evne if they are "that's the only way to do it" ;)

Thanks!
 
R van Vliet
Ranch Hand
Posts: 144
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nobody any suggestions?
 
Steve James
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
R van Vliet wrote:Nobody any suggestions?


I think that should be as "Anybody any suggestions" . kidding.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!