• 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

Synchronizing database record manipulation by multiple rmi clients

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

I have an RMI Server that allows clients to retrieve,edit and remove records from a database.

How do I make sure that not more than one client can edit an order at the same time?

So far the method below does all my database manipulation, but I don't think this is safe.



I am really new to Concurrency and Synchronization,

All orders are in a JTable and if you click the row a editor pops up, where a user may edit values and add products.
The JTable is updated every second by the event dispatcher if the table is currently visible to the user.

Please offer your advice as how I can safely allow multiple clients (up to 10) to view and edit records

Much Thanks,

David Weber

Using:
NetBeans 6.7
JDK 6
 
Ranch Hand
Posts: 116
Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"not more than one client can edit an order at the same time"
I think the answer is going to depend on what is meant by the "client" and what is meant by "at the same time". If all you are worried about is assuring that the database is in a consistent state then the answer is to set the isolation level to something appropriate and let the RDBMS deal with it. It doesn't look like you have anything longer than a single statement transaction so you shouldn't even have to start/commit transactions. This is where the definition of "at the same time" becomes important and this answer assumes it is defined at the database, not at the user's GUI.
OTOH, if you wanted to lock a row while a user (as in an actual person) was typing into it then the synchronization is significantly more complex. Locking any part of a shared database while waiting for a user action is most decidedly not recommended.
Before getting into something more exotic, look into transaction isolation and synchronization for your particular RDBMS and see if that will satisfy the requirement.
 
David Weber
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Chris,

What I've done is add a processing column to the orders table,

and when someone is editing the order the client app sets that order's processing to true,

and when the user exits the editor, the client app sets processing back to false.



If someone tries to launch the editor on an order that is being edited a Message pops up, to try again later.

I have added an override mechanism in case any orders get stuck on processing due to connection or app failure.

What do you think?

I know its not the safest and most efficient, but if only 10 users are using the system, this should suffice.

I only have about 6 months exp with Java and about 2 months exp with SQL.
 
Bartender
Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how do you decide that the processing was stuck?
Can 2 users see the same account together. The first locks and the second overrides?
It will probably be a good idea to give override permission only to administrators, if you have an authentication/authorization mechanism in place.

I hope you commit the transaction after updating the flag.
 
See ya later boys, I think I'm in love. Oh wait, she's just a 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