This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes JDBC and the fly likes how to maintain single transaction for multiple users Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "how to maintain single transaction for multiple users" Watch "how to maintain single transaction for multiple users" New topic
Author

how to maintain single transaction for multiple users

vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
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,


Thanks
Vipul Kumar
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36598
    
  16
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.
Madhan Sundararajan Devaki
Ranch Hand

Joined: Mar 18, 2011
Posts: 312

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.


S.D. MADHAN
Not many get the right opportunity !
vipul bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
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

Joined: Mar 18, 2011
Posts: 312

Well you can use Asynchronous request processing using Message Queues and JMS API.
Sudheer Bhat
Ranch Hand

Joined: Feb 22, 2011
Posts: 75
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 bondugula
Ranch Hand

Joined: Oct 14, 2010
Posts: 218
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to maintain single transaction for multiple users
 
Similar Threads
Stress\Load testing of a web server
java wacom tablet api?
any ideas for android tablet buying?
Java and Tablet PC
how install in Eclipse(Java/Android) emulator for Tablet PC Android