This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
  • 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

my question about LockManager.java

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,everyone:
I'm sorry for my English.
I feel well for meet you again!
In my assignment,
I don't know how to implement the LockManager.java?
in the LockManager.java file,which are those methods and attributes to need?
what's the mechanism to implement with those methods and attributes,
wait?
notify?
which do have the document for me to study?
thank you!
 
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jofer,
You can use a collection like Map, Set, List to hold record locks.
For example, in case of Map, a key can be a record number and a value could be a cookie.
Best,
Vlad
 
Jofer Chan
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,vlad:
thank you!
could you give me a simulation code for implements this function?
 
Vlad Rabkin
Ranch Hand
Posts: 555
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jofer,

could you give me a simulation code for implements this function?


I would like to let you publish your version of the code. Afterwards, I will comment and correct it if needed.
Best,
Vlad
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jofer,
I think one of the questions you should be asking yourself is "why do you want a LockManager?"
Once you have decided that, then you will start to see what methods should be in this class, and you can start thinking about how to implement them.
You may decide that you don't really need it though: many people do not implement a LockManager at all. I certainly didn't. There can be advantages to having one, but it depends on your design.
Regards, Andrew
 
Jofer Chan
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,Vlad and Andrew :
thank you!
sorry my English.
the follows is LockManager:
the codes referrence S. Ganapathy 's codes.

in the LockManager is singleton.
my question :
1.if don't use the LockManager,can I directness use the Lock/Unlock mechanism in the Data file?
2.if use the LockManager,in the Data lockRecord(long recNo) method invocation:

is right?
3.this is a basic question,I don't know how to implement it:
in lockRecord(long recNo) method,how to get the recNo?
no fields(name,location,specialties,size,rate,owner) to storage it in the DB.
4.the lockRecord(long recNo) method throws the RecordNotFoundException Exception,but this method don't read and write message to the db file,how to occur this Exception?
5.this question about the delete function,the db has 28 records,if deleted the sixth record,does the seventh record move along?
thank you.
[ December 03, 2003: Message edited by: Jofer Chan ]
 
Andrew Monkhouse
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jofer,


1.if don't use the LockManager,can I directness use the Lock/Unlock mechanism in the Data file?


Trying to grab someone else's code and use it could result in:
  • the code not fiting your requirements
  • you being unable to explain some aspect of someone else's code in your exam and you failing the exam!


  • If one of the questions in the exam is "Why did you decide to use or not use a LockManager?" how are you going to answer it?
    You may be able to use S. Ganapathy's code inside your Data class, but that depends on whether your Data class is itself a Singleton, a Multiton, or has no restrictions on number of instances.
    It also depends on whether your lock methods return cookies or not!
    Once you have worked out how you want your design to work, you can then look at what code you need to implement.

    2.if use the LockManager,in the Data lockRecord(long recNo) method invocation:

    is right?


    Does your unlock() method require you to throw RecordNotFoundException?
    How is your lock() method going to throw it? You do not do any validation on the record number - this could result in a failure.


    3.this is a basic question,I don't know how to implement it:
    in lockRecord(long recNo) method,how to get the recNo?
    no fields(name,location,specialties,size,rate,owner) to storage it in the DB.


    Perhaps this thread may answer your question.


    4.the lockRecord(long recNo) method throws the RecordNotFoundException Exception,but this method don't read and write message to the db file,how to occur this Exception?


    Check your instructions - they tell you the circumstances in which you must throw that exception.


    5.this question about the delete function,the db has 28 records,if deleted the sixth record,does the seventh record move along?


    No it should not.
    If a client is about to modify record number 7, and you move record 7 as a result of a deletion, which record will the client modify?
    It is much easier to just leave a logical blank space in the datafile, which may get reused later.
    Regards, Andrew
     
    Hoo hoo hoo! Looks like we got a live one! Here, wave this tiny ad at it:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic