-
Problème stock négatif
Bonjour ,
Je suis entrain de conçevoir un site de vente en ligne des bouquins avec l'architecture Struts2 -Spring- JPA/Hibernate.
J'ai confronté le problème du stock négatif .. j'explique :
Lorsque deux clients demandent quasiment au même temps un produit d'une quantité x , une vérification est déclenchée pour vérifier si le stock dispo est supérieur ou égale à la quantité demandée. Si deux opérations de commande de cette quantité x (et éventuellement d'achat) se passent au même instants , c'est évident que l'un des clients va épuiser cette quantité x avant l'autre, ce qui mène au problème de stock négatifs pour le 2ème client.
Donc j'ai pensé à faire obliger l'application de forcer l’existence d'un seul exemplaire d'un livre à un moment donné pour que l'accès à son stock disponible à un instant t. ( Exclusion mutuelle )
Suffit-il d'ajouter l'attribut singleton dans la déclaration du bean Action (Classe du traitement métier définie dans applicationcontext.xml) avec un traitement supplémentaire dans la méthode pour mutualiser l'accès ?
Y a-t-il une autre solution à proposer ?
Merci d'avance pour votre aide.
-
Si tu déclare tes connexion JBC comme serializable, tes transactions seront isolées et ceci sera impossible. A condition de bien tout faire en une seule transaction.