Dec 15th, 2012, 11:57 AM
Negative stock problem ( e-commerce )
I am trying to conceive it a website selling books online with architecture Struts2-Spring-JPA / Hibernate.
I confronted the problem of negative stock .. I explain:
When two customers order almost the same time a product of a quantity x, an treatment is triggered to check if the stock available is greater than or equal to the amount requested. If two control the quantity x (and possibly purchase) happen at the same moment, it is obvious that one of the clients will exhaust the quantity x before the other, which leads to the problem of negative stock for the second customer.
So I thought to force the application to force the existence of a single instance of every book at a given time for access to its stock available at time t. (Mutual exclusion)
Suffice it to add the attribute in the declaration of singleton bean Action (Class business processing defined in applicationContext.xml) with additional treatment in the method for pool (Mutualize) access?
There are another solution?
Thank you in advance for your help.
Last edited by meher211; Dec 15th, 2012 at 12:51 PM.