Results 1 to 3 of 3
  1. #1
    meher211 is offline Member
    Join Date
    Dec 2012
    Rep Power

    Default Negative stock problem !


    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 require almost the same time a product of a quantity x, an audit 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 access?

    There are another solution?

    Thank you in advance for your help.
    Last edited by DarrylBurke; 12-15-2012 at 03:11 PM. Reason: Removed annoying all-bold formatting

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Madgaon, Goa, India
    Rep Power

    Default Re: Negative stock problem !

    Don't format your entire post in bold as that makes it difficult to read. I've removed the bold tags.

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Voorschoten, the Netherlands
    Blog Entries
    Rep Power

    Default Re: Negative stock problem !

    Don't split the two actions (checking the amount of stock and adjusting the amount of stock) over two transactions.

    kind regards,

    Build a wall around Donald Trump; I'll pay for it.

Similar Threads

  1. The Stock Class
    By luckyirish in forum New To Java
    Replies: 9
    Last Post: 07-13-2011, 05:40 AM
  2. Stock exchange program
    By askinne2 in forum New To Java
    Replies: 2
    Last Post: 05-03-2010, 12:25 AM
  3. string to negative int problem
    By pendulum101 in forum New To Java
    Replies: 5
    Last Post: 11-01-2009, 06:47 PM
  4. Stock Quotes
    By BartDR in forum Advanced Java
    Replies: 0
    Last Post: 09-15-2009, 10:15 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts