I am maintaining medicine stock.In that the availability of crocin tablet is 50.
2 or more users requesting the crocin tablet at the same time.It shows the availability to all users as 50.
But my intention is while issuing the crocin tablet to the first user then how to display the updated available quantitiy to other users.
You have already answered that, because the thread title says that. You can create a transaction in your update procedure. Alternatively you can put a lock on the database while the number is being altered, and take the lock off again when the update is complete, but I think a transaction would be easier.
When showing the current stock to all, all will be shown 50. However, when each one of them starts requesting for tablets, you need to have a synchronized block/method that will allow the stock to be updated based on the availability of the tablets.
I can maintain synchronized method/block.But all the other threads need to wait when a thread is accessing the method/block.
That will show impact on Application Performance,right?Is there any other alternative..
In your issue method/procedure you need to acquire the lock on the row that has available quantity for Crocin. So the pseudo code would look like below.
select the available quantity with the FOR UPDATE clause.
if available quantity >= requested quantity
logic for issuing the medicine, followed by update of available quantity.
else
raise an exception saying requested quantity cannot be fulfilled with current onhand.
I am using Ajax request when clicking on submit button.If the first user updates the data then second user will be getting the alert telling him the available quantity is empty.
My Application is limited not distributed.And so no need of using JMS API.Once Again Thanks for your replies.
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
a bit of art, as a gift, that will fit in a stocking