aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes My Locking Approach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "My Locking Approach" Watch "My Locking Approach" New topic
Author

My Locking Approach

Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Ok I guess strictly speaking you could say that I am not fulfilling thhe requirements.


Any attempt to lock a resource that is already locked should cause the current thread to give up the CPU, consuming no CPU cycles until the desired resource becomes available.


I guess I do consume some CPU cycles when checking if the resource I require is available.

Could you explain a bit more how your solution works ?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

As a side note, candidates have passed with 100% for their locking solutions even though they did not strictly meet that criteria.

And candidates have received the 44/80 score even when they have ensured that no CPU cycles are being consumed.

There are several easy answers to ensuring that no CPU cycles are consumed, but I am not convinced that they are worth spending a lot of time on.

Regards, Andrew


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

Joined: Apr 18, 2005
Posts: 113
Well if 80/80 can be achieved they I reckon I'm gonna leave it the way it is.

Thanks for the input Andrew.
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Evaluation criteria regarding locking is fuzzy. Other candidate experiences make me think that most of examiners are mainly taking into account automatic tests, and few of them look deeper into the code.
Why only 44/80 or 80/80 marks?


SCJP, OCMJD, OCMJEA
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11481
    
  94

Originally posted by Oricio Ocle:
Why only 44/80 or 80/80 marks?


cryptic answer

Regards, Andrew
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Ok, so all my work and effort become a black box for the testers
Thanks Andrew for your useful replies
Regards
Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi Alen,
If the error occurs in the Network layer I throw a RemoteDataException which also extends RuntimeException.
I made this distinction just to make it obvious where the error is occuring.
Could you please give out an example for such error?


SCJP 1.4 SCJD
Alan Morgan
Ranch Hand

Joined: Apr 18, 2005
Posts: 113
Originally posted by Zhixiong Pan:
Hi Alen,
Could you please give out an example for such error?


RemoteExceptions that are thrown are just repackaged as RemoteDataExceptions.

Does this make sense ?
Pawel Poltorak
Ranch Hand

Joined: Sep 21, 2005
Posts: 36
Ok, so all my work and effort become a black box for the testers [pissed]


In my opinion this is not fair. I recently got 44 points for locking. I had some assumptions, which I documented, like only one lock per client, not taking care of the stalelocks. If locking is tested as black box, then these assumptions might be taken as errors, which is inappropriate, since they are mentioned in choices.txt.

Best Regards,
Pawel


SCJP, SCJD
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Hello again Pawel

You wrote:
In my opinion this is not fair. I recently got 44 points for locking. I had some assumptions, which I documented, like only one lock per client, not taking care of the stalelocks. If locking is tested as black box, then these assumptions might be taken as errors, which is inappropriate, since they are mentioned in choices.txt.


When a i said: 'all my work and effort become a black box ' I was talking about the 'consume some CPU cycles' issue.
IMO this is very difficult to know in a automatic test.
Regards, Ori
[ April 04, 2006: Message edited by: Oricio Ocle ]
Sergey Zolotaryov
Greenhorn

Joined: Mar 14, 2006
Posts: 26
I do not synchronize any data access methods in my solution. For the purposes of record locking I used a LockManager, which utilizes ReentrantLock and Condition for record locking/unlocking and a map of Long -recordNumber and Cookie objects, which store cookie values, conditions and number of threads waiting for a particular record. When a record is unlocked by some thread, it signals only to one thread, so that others "do not consume extra CPU cycles".

The file access part is synchronized through a read/write access pool (which a real database would use). This pool contains a number of readonly RAF instances and one RAF instance for writing. Every file access method, like find or read, or update, must obtain read of write access from this manager facility. So I can have multiple readers at the same time, which do not interfere with one another. Although on the file-system level its all the same, I mean that on windows each IO operation happens sequentially, but on a linux with RAID HDD this might be a bonus to the system's overall throughput. Write operations are the operations that really need to be synced, so when a write access is asked, it waits until all readers finish their jobs and then write access is granted.

This all sound too complicated, but the implementation is really a couple of lines for each access granting method Thanks to java.util.concurrent.ReentrantReadWriteLock, God bless the library authors.

As for the IOExceptions, I wrap them in unchecked and declare in the javadoc. With a little BUT. My business layer, which does the read/find/book stuff, catches these unchecked exceptions and re-throws them as checked ("unwraps" them). So my client does not have to rely on fuzzy assumptions and catches real IOExceptions. I think, my idea is good enough, what do you think?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: My Locking Approach