This week's book giveaway is in the Design forum.
We're giving away four copies of Building Microservices and have Sam Newman on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Making sure I have this dead lock concept without statics correct Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Building Microservices this week in the Design forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Making sure I have this dead lock concept without statics correct" Watch "Making sure I have this dead lock concept without statics correct" New topic
Author

Making sure I have this dead lock concept without statics correct

Rick Reumann
Ranch Hand

Joined: Apr 03, 2001
Posts: 281
Just so I have this clear..in the code below if the two objects had NOT been defined as static then a deadlock situation couldn't occur could it? Since each Thread object would have it's own Test object and thus it's own instances of obj1 and obj2 they would never get locked since m1() and m2() would always be waiting to be finsihed before the next one was called. (I would think the output could still not be determined, though, regardless of whether the Objects obj1 and obj2 were static or not).
Jose Botella
Ranch Hand

Joined: Jul 03, 2001
Posts: 2120
I agree. If variables were non static, methods wouldn't be synchonized at all. And no deadlock would be possible. The same object must be used for properly synchronization.


SCJP2. Please Indent your code using UBB Code
 
Have you checked out Aspose?
 
subject: Making sure I have this dead lock concept without statics correct
 
It's not a secret anymore!