File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes LockManager Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "LockManager" Watch "LockManager" New topic
Author

LockManager

Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
I have implemented a lock and unlock in a LockManager in my design. Reading this thread and Max first comment is
The second approach is to change the method signature on the lock/unlock, and explicitly passing in a client ID. The advantage here is that you're not tied into your networking implantation, that thus have a more robust solution. In a production enviroment, where I had some leeway, this is probably the way I would choose.
The disadvantage here is that you risking an automatic failure, since you're not, by definition, implementing the methods lock(int) and unlock(int), but rather two different methods, with different signatures, that you find to be more convenient.

Now, the information from Sun is :
Part of your assignment will be to enhance the Data class. You may do this by modification or subclassing, but you should document the approach and reason for your choice.
You are required to implement the criteriaFind(String)
, lock(int)
and unlock(int)
methods:

Question. Can I use the lockmanager or am I toast here?


Free software is a matter of liberty, not price.
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937

Question. Can I use the lockmanager or am I toast here?

Yes, by all means use lock manager. In fact, with lock manager, you don't need to modify the signatures of lock/unlock.
Eugene.
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
How do you mean?
I have a Data and LockManager in a in a RemoteDataImpl. If I do lock / unlock on the lockmanager and do not use the anything in data then....what? Or do you mean that I should use the lockmanger and after I made a lock on the manager I make a look in data aswell? Should I have a Hashmap with locks in Data too? I am confused....
Kevin Cao
Ranch Hand

Joined: Jun 19, 2002
Posts: 55
Raffe,
This is my thought: in your connectionFactory, you will return a dataInterface object, but its true type will be determined at runtime. Somewhere in your business logic you will do a lock-read-modify-unlock sequence, instead of checking
you can go ahead to do this regardless of the type. Lock/unlock in Data class are just dummy methods. Just my 2 cents.
HTH
-Kevin
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
Kevin, My question is : Can I manage without implementing anything in the Data lock/unlock methods?
Kevin Cao
Ranch Hand

Joined: Jun 19, 2002
Posts: 55
Raffe,
I don't quite understand what you mean by "manage". I think your confussion is this(ignore this if I am wrong): you have a Data instance in your RemoteDataImpl, and you implement the locking schema in RemoteDataImpl.
From Max's book:
Locking an object does not lock member variables of that object.

But your locking schema is against RemoteDataImpl

"this" here is the RemoteDataImpl, so there is nothing to do with Data. One of the reasons people implement locking in Data is they intend to lock/unlock in local mode.
Kevin
Max Habibi
town drunk
( and author)
Sheriff

Joined: Jun 27, 2002
Posts: 4118
Originally posted by Raffe Paffe:
Kevin, My question is : Can I manage without
implementing anything in the Data lock/unlock methods?


Raffe,
No one here can answer that question for you. Some people have refused to implement
lock/unlock in Data, and done well on the exam.
However, most of those people will admit that this is not a strict reading of the requirements.
Others, and I fall into this category, read the requirements strictly, and implemented
lock/unlock in the data class.
On the one hand, Sun probably will not fail you if don't implement lock/unlock in data.
on the other, they could chose to, because you didn't follow directions, and they would
be within reasonable behavior to do so.
Since the logic of the code is the same, I would suggest that stick with the strictest
definition. They said to implement lock/unlock in Data, so do what they asked.
That way, you can't be faulted.
All best,
M, author
The Sun Certified Java Developer Exam with J2SE 1.4
[ March 10, 2003: Message edited by: Max Habibi ]

Java Regular Expressions
Raffe Paffe
Ranch Hand

Joined: Feb 24, 2003
Posts: 92
Max, thank you. I will try to move my lock/unlock code from the lockmanager to data.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: LockManager
 
Similar Threads
why is it necessary for unLock() to check clientID?
Once again about locking
Implementing Lock/Unlock using Event delegator
design comments ...
Record locking must be implemented using the methods public void lock(int) and public