• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LockManager

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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....
 
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kevin, My question is : Can I manage without implementing anything in the Data lock/unlock methods?
 
Kevin Cao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
town drunk
( and author)
Posts: 4118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Raffe Paffe
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic