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 urlyBird testing lock Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "urlyBird testing lock" Watch "urlyBird testing lock" New topic
Author

urlyBird testing lock

jiju ka
Ranch Hand

Joined: Oct 12, 2004
Posts: 306
I have two versions of test script for testing locking.
One version finds the error. Other not.
There is no significant difference between the two.
I like to know why the two programs are showing the difference.


code for version 1



The out put for above code is


The second version of code just have changes as follows


But this is not catching the error
The output follows

Please note code in case0, case1, case2 and execute are identical(cut and paste).
Reason for the failure of lock is in the way I use synchronization.
lock method is having synchronized modifier which is wrong. I should be synchronizing on a common object (like a collection of locks or a non duplicated/cloned single lock) to all threads.

Extremely curious :roll: to know the difference. I am not giving the lock or unlock details which may deviate attention. The lock acquiring event is not logged for the same reason.

Any help is appreciated.
[ April 14, 2005: Message edited by: jiju ka ]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: urlyBird testing lock
 
Similar Threads
Please Help -- Question on testing lock() with multiple threads
Can you still access an unsnychronized method even when there is a lock on the object?
Design Questions
Locking and remoteException
Question about Unreferenced