• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to maintain single transaction for multiple users

 
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,

In my project i have a scenario.

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.

Thanks in Advance,
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks For Your Reply,

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..
 
Madhan Sundararajan Devaki
Ranch Hand
Posts: 312
MS IE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you can use Asynchronous request processing using Message Queues and JMS API.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.

commit;
exception
clean up;
rollback;
 
vipul John
Ranch Hand
Posts: 253
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks EveryOne for your Reply,

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
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic