Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

concurrent access to DB

 
Mohammad Ashari Rahman
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
say I want to access a record in DB and another person in other place wants to do the same, how can I apply using C++/Java concurrent accesses ?

Just can tell me the concepts involved and algorithm if possible

thanks
 
chris webster
Bartender
Posts: 2407
33
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are both reading the data, then that should not be a problem as any proper database will support concurrent reads.

If one of you is modifying the data, then the other person may see old data until the changes are committed. They would then need to re-query the record to see the changes, although these days some platforms will "push" changes to subscribers so that they see them immediately.

If you are both trying to change the same record, then you need to start thinking about things like locking strategies i.e. what do you want to happen if two users are trying to modify the same record at the same time? Should the first change win? Should both fail?
 
Marco Behler
Author
Ranch Hand
Posts: 43
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mohammad,
have a look at the code examples from my book. Everything you need to know regarding locking: http://www.marcobehler.com/make-it-so-java-db-connections-and-transactions-html/plain-jdbc-multiple-users-and-deadlocks-inserts-1.html

Cheers
marco
 
Mohammad Ashari Rahman
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic