aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Deadlock testing class for B&S 2.2.1 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 "Deadlock testing class for B&S 2.2.1" Watch "Deadlock testing class for B&S 2.2.1" New topic
Author

Deadlock testing class for B&S 2.2.1

Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 176
The following is adapted from Bob Perillo's original class which was used for Urlybird. Anyone utilisng this class will probably have to make some
adjustments, especially in the FindingRecordsThread() method. One area where your code may differ is that I did my unlocking in a finally block
and I also used a cache map to cut down on I/O. The loop can be increased to whatever you like and exceptions will be thrown dependant upon
input. The program should complete fairly quickly and if it sits there hanging this probably indicates deadlock.

Hope others find the class useful.

Cheers Kevin.



Java5 Tutorials | Java6 Tutorials | HTML/CSS Tutorials | JavaScript and jQuery Tutorials
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5406
    
  13

Kevin,

Does your unlock method doesn't throw any Exception, like a RecordNotFoundException for example?

Because this code in my program result in compiler errors. And adding try/catch block in the finally-block seems a little bit crappy


It could be of course that our assignments differ at that point


SCJA, SCJP (1.4 | 5.0 | 6.0), SCJD
http://www.javaroe.be/
Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 176
My unlock() method throws a SecurityException when the passed cookie doesn't match the cookie held in the locking map.

My Sun DBAccess interface for unlock() method is:

Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5406
    
  13

And i guess your SecurityException is a checked exception... But how could this code compile in your test-case? Or maybe i'm missing something here but i would expect a try/catch around the call to unlock in the finally block

Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 176
Sorry Roel not quite sure what you mean here? And my SecurityException class extends RuntimeException.

My lock/process/unlock method calls are delegated to my Data class. so my RemoteServicesImpl class calls the following on the Data singleton
delegated on SERVER mode startup



I don't call unlock() within say the Update() method. But yes the whole lock/process/unlock is within a try block.

Both these classes throw either a ServicesException/RemoteServicesException so when the Data instance is called this is also
wrapped in a try/catch block.
Roel De Nijs
Bartender

Joined: Jul 19, 2004
Posts: 5406
    
  13

Hi Kevin,

I was just wondering why your deadlock testing class compiles, but if your SecurityException extends RuntimeException (like you said), then that's the reason why. I thought that your SecurityException was a checked exception (like i did myself in my code, but with the RecordNotFoundException), so i was a bit amazed that your code did compile.

So you solved the "mystery"

Kind regards,
Roel
Lukas Jenny
Greenhorn

Joined: Oct 12, 2008
Posts: 8
Hi,

Thank you very much for your Test Class.

As I'm currently doing the Version 2.3.2 of the B&S assignment I had to adapt it a bit. Now it runs without exception on my code. I hope this still means that my locking is ok.

btw: Do we have to note the first comment in every class? I can't remember having read something like this...

Best regards
Lukas Jenny

Kevin Florish
Ranch Hand

Joined: Jan 06, 2009
Posts: 176
btw: Do we have to note the first comment in every class? I can't remember having read something like this...


No you don't is the simple answer, it's just there for clarity.
Lukas Jenny
Greenhorn

Joined: Oct 12, 2008
Posts: 8
Hi Kevin,

Ok, thanks for your answer.

best regards
Lukas Jenny
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Deadlock testing class for B&S 2.2.1