Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Is deadlock a big threat ?

 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Each time I see an exemple of Deadlock in a book, I think :"How god, what the hell went inside his brain to design such a solution". Even with all warnings about deadlock on SCJD. in my SCJD, I don't see how you could create decently a deadlock, except maybe using notify() instead notifyAll().

Am I too confident ?
 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe you are, ( or I'm just too newbie )

It will depends of what strategy you will use in your project. Maybe some distraction could leave you into one deadlock situation, all books they approach only a deadlock situation, with a poor context, because what matter is the deadlock and not the entire application. What I mean is that the book examples didn't cover all situations , they just lead you into the best practices. On my project I discover a dead lock issue, weeks before upload my project ( thanks do Perillo test suit ), and I was impatient to upload and finish it. I try to investigate and notice that I was using mutex locks to some I/O methods, to write and upload the records. Then I simply synchronized the methods and it works fine...... When it was teste with 20, 30 clients it works fine.... But in the test suit, with lots of threads, It locks =/.

The advice is, do not underestimate the locks and test every piece of code.
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just, as a matter of interest. Created a deadlock situation today, using notify instead of notifyAll while calling unlock() while using multiple threads. That's 1 example.
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nicolas,

I think trying to avoid the deadlock in this assignment is one of the big tasks. My initial code was also not deadlock-proof when I ran Roberto Perillo's test case. It's very easy to end up with code that possibly could deadlock (from my own experience). So I would be not too confident about it. If you are able to run Roberto's test with different counters (1, 10, 100, ..., 10000) and they all complete, I'm sure you are safe

Kind regards,
Roel
 
Bartender
Posts: 2292
3
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm glad to know that the code I created to test this part of the assigment is being helpful to everybody!

Now, Nicolas, I see this as a big opportunity to learn more about concurrency, because there are a lot of forms to implement it (take a look at the java.util.concurrent package and its subpackages), including the classical synchronization. Indeed, this is the hardest part of the assignment, so be careful with that.

I still didn't have the opportunity to read it, but I just found the Java Concurrency in Practice book, and as far as I could see, it is really really good. It can be a good resource for reseach!
 
Nicolas Zozol
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've implemented the Lock stuff at the end of the program and launched the unit-test.

Guess what, I have a deadlock
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
At least now you can fix it It's good that you've found it before you submit it

Regards,
Nicolas
 
Nicolas Zozol
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I spent all the day on deadlocks

I resolved it quickly with ReentrantLock.

The downside of this is that I lock every records when I une the lock(int recNo) method :



In my comments, I will add that ReentrantReadWriteLock might be more efficient if it's needed. But it may affect the design of the interface.

Good point : it passes the Thread test with 2000 loops. It looks like I'm almost done with this program
 
Don't MAKE me come back there with this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic