Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General 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 ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Lock / Unlock Overview

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

This is my first message on this forum so be kind to me
I just started the Developer assignment a couple of days ago and I have resolved the depracated methods. I have now moved onto the lock/unlock methods. Would I be right in saying the following:
- The lock/unlock methods are primarily for locking individual records in the db file.
- I was thinking about using something like a Vector to keep control over which record numbers are locked or not.
- The majority of the other methods in the Data class are synchronized, presumably that is to keep control over the access of the file pointer (so only one thread can have access over the file at one time only).
Couple of questions though:
- Should there be some way to ensure that the Threads obtain a lock first on a record?? What I mean is that Thread A obtains a lock on a record and proceeds to modify, while Thread B could come in and go straight to modifying a record with out a lock?
- Do you have to check that a record is locked in every method that involves writing/reading/deleting to the db file??
- Would it be best to synchronize the lock/unlock method or just have a synchronized block on the container (Vector) that I plan to use for record number storage??

Hope you can add any comments to the above,

Thanks for your time,
Stuart
 
No prison can hold Chairface Chippendale. And on a totally different topic ... my stuff:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic