permaculture playing cards*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes my question about LockManager.java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "my question about LockManager.java" Watch "my question about LockManager.java" New topic
Author

my question about LockManager.java

Jofer Chan
Ranch Hand

Joined: Sep 09, 2003
Posts: 49
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!
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
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

Joined: Sep 09, 2003
Posts: 49
Hi,vlad:
thank you!
could you give me a simulation code for implements this function?
Vlad Rabkin
Ranch Hand

Joined: Jul 07, 2003
Posts: 555
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
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11503
    
  95

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Jofer Chan
Ranch Hand

Joined: Sep 09, 2003
Posts: 49
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
Marshal Commander

Joined: Mar 28, 2003
Posts: 11503
    
  95

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
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: my question about LockManager.java