Two Laptop Bag*
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making sure I have this dead lock concept without statics correct
 
Similar Threads
Question ID :988384705515 JQ+
Deadlock / Object Lock ???
Basic thread doubt
Object lock Question
Reg. Some Thread basics