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 NX: A few questions. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "NX: A few questions." Watch "NX: A few questions." New topic
Author

NX: A few questions.

Larry Li
Greenhorn

Joined: Nov 25, 2002
Posts: 27
Hi,all.
My assignment is URLyBird 1.1.1, it's an early version of new ones.I got it last April, I put it off about half a year and want to finish it now, i've read lots of threads on many topics, they're really helpful, thank you all.
Here are some questions that still confused me, thanks any help or comments.
1. about lock-delete-unlock,how to avoid RecordNotFoundException in unlock method.
I've read this thread:
http://www.coderanch.com/t/184241/java-developer-SCJD/certification/NX-URLyBird-lock-delete-unlock
Vlad suggested to do unlock in delete course, I'm not quite agree with that,I think "each method should do his own job",it is not proper for delete() to unlock a record, and even we can do this, how can a delete() throw a SecurityException(unlock check it)?
2. about locking, I now use a HashMap(Integer(recNo),Long(lockCookie)) to store locked records, but after read some articles on this topic, I found it can do nothing when a client crash occurs. But I don't know how to use a weakHashMap, because both recNo and lockCookie have to be stored.
3. In my implementation, both stand alone mode and server mode are involved in locking course, is this permitted? Or the alone mode need to by pass the entire locking course?
Thx for any reply


The hill is not a hill.
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

1. Well delete does have an interesting thing. First I think it should just check to see if that record is locked by any user, if it is, then throw an Exception. If it is not then it should just delete the record and not lock and unlock it. Also Delete is not a feature that is implemented on the client, so the wait of this method isn't too high in the grading.
2. WeakHashMap is good and really should have any difference from using a regular HashMap, but I would still also look into the Unreferenced interface. I thought the Unreferenced was way too easy to implement and that is what I like.
3. In local mode there should be no locking.
Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Larry Li
Greenhorn

Joined: Nov 25, 2002
Posts: 27
Thx Mark.
I think I need to look through more threads about lock implementation, unreference and WeakHashMap are new to me, no matter which method I finally use, I will learn both of them.
3. In local mode there should be no locking.

update(int recNo, long cookie), so in alone mode, I can pass a predefined cookie value to indicate that, and update without check lockMap, is that right?
Wagner Danda Da Silva Filho
Ranch Hand

Joined: Mar 21, 2003
Posts: 80
Originally posted by Mark Spritzler:
3. In local mode there should be no locking.
Mark

Mark,
I couldn�t find that statement in the text. It's obvious that there is no need to use such mechanism in local mode, but I don�t think it�s right to "disable" the locking.


SCJP, SCWCD
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Larry,
1. Agreed (with you).
(Mmh... don't repeat it, but I made this first answer very short and simple just to make Mark happy.)
2. about locking, I now use a HashMap(Integer(recNo),Long(lockCookie)) to store locked records, but after read some articles on this topic, I found it can do nothing when a client crash occurs. But I don't know how to use a weakHashMap, because both recNo and lockCookie have to be stored.

It's not obvious, but think of the fact that lock cookies could represent the client. Now if you want to use a WeakHashMap to track client crashes, you could inverse the key/values and/or use another object to represent the client. This thread may help you.
3. In my implementation, both stand alone mode and server mode are involved in locking course, is this permitted? Or the alone mode need to by pass the entire locking course?

A large majority of people around here think that locking shouldn't be bypassed in stand alone mode (simpler to debug and maintain at the cost of a non measurable overhead). But it's OK if you do.
Best,
Phil.
[ November 17, 2003: Message edited by: Philippe Maquet ]
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
I agree with Wagner that locking in local mode is perfectly acceptable. In local mode the locking may not actually matter, because there's no other client that can lock records. So a single well-behaved client should have no real need for locking. But there's no need to avoid it either. Many of us have an adapter or facade somewhere in the design (client or server) which abstracts out the details of locking. If this class is separate from the networking code, there's no reason not to reuse the same code for both standalone and networked use. For many of us it would be more work to disable the use of lock and unlock, than it is to just keep it in even if it's unneeded.
Hmmmm, looking again at the requirements - if you've got an API that says, for example, that update() should throw a SecurityException if it's called on a record which hasn't been locked, then you're pretty much required to use locking in order to use update(). Even if there's no other client to guard against.


"I'm not back." - Bill Harding, Twister
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hmmmm, looking again at the requirements - if you've got an API that says, for example, that update() should throw a SecurityException if it's called on a record which hasn't been locked, then you're pretty much required to use locking in order to use update(). Even if there's no other client to guard against.

Good point !
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: NX: A few questions.
 
Similar Threads
UrlyBird Passed (381/400)
NX: URLYBird / my approach of the reading problem
NX: ?mark about Locking of NX
NX: URLYBird - Use of findByCriteria(String [ ])?
NX: Exam review (URLyBird 1.1.2) !!!