Win a copy of Microservices Testing (Live Project) this week in the Spring 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Making sure I have this dead lock concept without statics correct

 
Ranch Hand
Posts: 281
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic