Win a copy of AWS Security this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger

Have I misunderstood the locking concept?

Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I'm in final touch to the project. I don't know whether I misunderstood the locking concept. My lock method will lock whole database, so other thread has to wait till the thread which has locked the database release it.

My design is if thread A locked record 5, no other thread can lock any other record.

I think I've to implement like this:
If Thread A locked record 5, all other threads are allowed to lock any record other than record 5.

Please help me.


Ranch Hand
Posts: 221
Scala Python Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Seetha,

Read the FAQ and in special here.

You need to provide logical record level locking granularity so multiple clients can access your database concurrently
and at the same time (Client A locking record 5, Client B locking record 10 and so on).

In my honest opinion, with that approach locking the entire database, you are serializing all the access to the database
and most likely you will fail or get a very, very low grade as far as the locking requirements go.


Posts: 11604
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the output of the multi-threaded server would look like this (of course this output is not guaranteed, because order can change):

client1 locks rec4
client2 locks rec5
client1 updates rec4
client3 locks rec6
client3 updates rec6
client1 unlocks rec4
client2 updates rec5
client2 unlocks rec5
client3 unlocks rec6

And if a similar output is not possible with your current code, I think you'll fail because your locking mechanism is not according to the instructions. And also imagine a mix of reads and finds interfering with this scenario (so between locking of rec4 and rec5 other clients can read rec10, create rec341, find all records in Paris,...)
Seetharaman Iyer
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Carlos & Roel . This really helps me a lot. I'll deal it with creating new HashMap.
There are 29 Knuts in one Sickle, and 17 Sickles make up a Galleon. 42 tiny ads in a knut:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic