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

Tracking client id for database lock

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does anyone know a good way to implement this.
It's says in the assignment documentation that you should implement public void lock(int) and public void unlock(int). How I'm I then supposed to be able to track which client that is trying to lock and unlock the current record? Using the current threads name doesn't seem to be a adequate solution.
Any suggestions?
 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could never how to figure this out, but some people use custom socket factories to do this. I would search this NG for those messages.
The other way is that some people modify the signatures of the lock/unlock methods.
 
Marre Mask
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rick Fortier:
I could never how to figure this out, but some people use custom socket factories to do this. I would search this NG for those messages.
The other way is that some people modify the signatures of the lock/unlock methods.


Are you really allowed to change the signature of lock(int) and unlock(int)? It's says in the instructions "Record locking must be implemented using the methods public void lock(int) and public void unlock(int)".
 
Rick Fortier
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that it is best not to change the signatures. I did not. Others have and have passed.
There are two conflicting requirements, identify the connection for unlock is the same as lock, and the method signatures. Unless you come up with a complex answer, you will probably have to violate one or the other of these rules.
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this as a solution to this. It works and is not complex.
Dont put any of the lock/unlock checking code in your Data class. Instead put this in whatever class you're using to do remote data access. Have a signature in that class that allows you to check who locks/unlocks appropriately and depending on that you can then call the non-checking lock/unlock methods in the Data class (ie at the server end). That way all remote lock/unlocks will be checked and local lock/unlocks don't really need checking.
Akanimo.
 
I RELEASE YOU! (for now .... ) Feel free to peruse this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic