• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Causing deadlock

 
William Smith II
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm close to handing in my assignment. It appears to be free of deadlock. But I'm trying to actually cause deadlock with a multi threaded tester I wrote. I want to cause deadlock so that I know that I fully understand the code. Then when I hand it in, I'll revert the code back to how I think it should be.

I changed both lock() and unlock() to use notify() in their syncrhonized blocks, instead of notifyAll(), which in theory should cause deadlock. Since if thread A wants recNo=9 and then sends a notify(), and the JVM chooses thread B, that also wants recNo=9, that would cause deadlock.

I deleted all my records from my DB file except one record. Therefore if I run with 500 threads, they should all be waiting on recNo=1, since that's the only on out there.

Unfortuantely, my program runs without deadlock. What am I doing wrong, and why can't I get my program to deadlock?
 
William Smith II
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had my thinking wrong on this. If I only have one record, then I wouldn't have deadlock.

But with the original file (30 records), and 500 threads running, I'm still not seeing deadlock. So I'm still confused.
 
William Smith II
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind this thread, I completely went off on a tangent today I guess being days away from handing it in, and you think you've got concurrency straightened out, will do that to you! For what it's worth, I do believe I've got concurrency straight in my SCJD. Just one of those days...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic