• 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
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
  • Himai Minh
  • Carey Brown
  • salvin francis

Fundamental Locking Question

Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am only thinking about the locking mechanisims at the time, and had some very fundamental questions I would like help on before I start coding.
First, how does locking work - specifically, what do I synchronize on? I was planning on reading all the flights into a Hashtable keyed by the flight number, and sync'ing on the objects inside the Hash. i.e.
flight = flightHash.get(flightNumber)
synchronized (flight) {
// Once we get in here, we know we
// can change this flight without interuption

When I read these forums you all talk about a LockManager class. My impl doesn't seem to need a lock manager, it simply sync's on the Hashtable elements. Am I missing something??

My second question relates to the first one. Is it a good idea to store all the flights in a HashTable; or should I lookup flight info from the Data class EVERY TIME a user does a search, lock, etc?
[ October 29, 2002: Message edited by: Dave Teare ]
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Dave,
IMO, you don't need a lockmanager, unless it helps you think through the problem. In you case, it doesn't seem like it's neccessary. However, I'm not sure you need to lock on the items in your hashmap either. Depending on your implementation, you could just make the hashmap static, and simple insert elements into it as you need them(using either the client ticket or Thread as a key, and the recordno as the value).
The approach you're talking about has a nested lock structure(once for the map, then again for the element in the map), which, if I'm reading it correctly, is dangerous design, potentially opening the door to deadlock.
all best,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
Dave Teare
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your input! I'm glad to see I am not completely out in left field
I might still use a LockManager just because it seems to provide a clean seperation; I just wanted to make sure I used it for the right reasons.
    Bookmark Topic Watch Topic
  • New Topic