Win a copy of Fixing your Scrum this week in the Agile 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
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

deadlock or

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
Actually this is an interview question
I would like to know if say there are many threads trying to access a synchronized method of a object & say if thread 1 dies in the synchronized mehtod. What are the repercussions of this & what will be the solution.
Rgrds
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'd have to define what you meant by "dies" (not a technical term!)
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey
Even i had to face this qstn in 1 of my intrvws .
still wondering wat wil b the answer.
wel regarding die i reckon wat he wants to say if the thread gets detroyed or suspended
Rgrds
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, if "destroyed" means destroy() is called, and "suspended" means suspend() is called, then the answers are rather different in those two cases; and there are other possible definitions of "died" as well, each with different meaning (stop(), wait(), sleep(), throwing a RuntimeException) If he wants an answer to one particular case, then I'll be glad to provide it; but if he wants to know the answers to all possible cases, then it probably makes more sense to read a book on the topic.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest
Here is the question put to me.
Say in a synchronised method i have teh database connection code
There arew many threads waiting to access this synchronised method.
Now the connection is obtained & say immediately the db goes down
Isnt this a deadlock scenario
How will you handle such a scenario
Rgrds
MD
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by mahendra dubey:
Say in a synchronised method i have teh database connection code
There arew many threads waiting to access this synchronised method.
Now the connection is obtained & say immediately the db goes down
Isnt this a deadlock scenario
How will you handle such a scenario


First this not a deadlock scenario(this is not called a deadlock scenatio).This threads will wait indefinitely till the database is up or timeout occurs(if enabled).
Coming to handling such situations, you can check whether the db is up by putting some timeout for connection. When timeout expires, tell the user that db is down.
 
Idly Vada
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sanjay dube:
I would like to know if say there are many threads trying to access a synchronized method of a object & say if thread 1 dies in the synchronized mehtod. What are the repercussions of this & what will be the solution.


Java uses monitors to thread synchronization. If one thread using the synchronized method gets destroyed,it will release the monitor key.This key can be used by other thread waiting. I don't think deadlock will occur in this situation.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Murthy Narasimha writes:
If one thread using the synchronized method gets destroyed,it will release the monitor key.


While this is essentially true in practice, it's not true in theory; I point this out because you use the word "destroyed". If you call destroy() on a Thread, in a JVM that actually implements destroy(), then the Thread will go away but any monitors it holds will not be released! Now, of course, Sun's JVMs, and therefore most if not all JVMs, don't actually implement destroy() -- they throw an UnsupportedOperationException if you call it.
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic