This week's book giveaway is in the Artificial Intelligence and Machine Learning forum.
We're giving away four copies of TensorFlow 2.0 in Action and have Thushan Ganegedara on-line!
See this thread for details.
Win a copy of TensorFlow 2.0 in Action this week in the Artificial Intelligence and Machine Learning 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
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

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.
researveFlight(flightNumber)
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?
Thanks!!
--Dave.
[ 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.
--Dave.
 
What? What, what, what? What what tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic