The Artima Developer Community
Sponsored Link

Java Answers Forum
whats a deadlock ?and where and when does it happen??and how to rectify it?

2 replies on 1 page. Most recent reply: Aug 19, 2002 6:00 AM by Keshav

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
senthil

Posts: 23
Nickname: rickk84
Registered: Aug, 2002

whats a deadlock ?and where and when does it happen??and how to rectify it? Posted: Aug 18, 2002 8:44 AM
Reply to this message Reply
Advertisement
whats a deadlock ?and where and when does it happen


Keshav

Posts: 11
Nickname: kesh
Registered: Aug, 2002

Re: whats a deadlock ?and where and when does it happen??and how to rectify it? Posted: Aug 19, 2002 5:58 AM
Reply to this message Reply
Hi Senthil,

Before we come across the meaning of Deadlock .. Well u know that a printer is a shared device. When one job is printed the other's cannot print it unless & untill it completes.

Same way when we have a thread which calls on a sycrhonized method. We say it enters the monitor. Unless & untill the Thread completes the execution no other thread can enter the monitor( I mean call the method)

U will be having many resources like the printer to be shared.

Now assume that u have two resources A & B, U also have two threads X & Y. X calls on a <b>synchronized </b>method & enters the monitor A which is holding the resource A. Just after that Thread Y calls another <b> synchronized </b> method which enters another monitor B which is holding the resource B.

Hope ur clear with this. Now we have a stituation where the both the threads have entered the monitor. Now Thread A needs to make use of the resuorce which is presently occupied by Thread B. So it waits for Thread B to come out of the monitor. Thread B which cannot complete the task bcoz it needs the resource which is occupied by Thread A. So it also waits.

Both the threads are in wait state. This waiting will never get over. This is called DEAD LOCK

There is no solution for Dead Lock, while coding the programmer has to carefully handle the code in such a way that deadlock doesn't exits.

Hope ur clear with the explanation

<i><b>Cheeeeeeeeeeers

Keshav</b></i>

Keshav

Posts: 11
Nickname: kesh
Registered: Aug, 2002

Re: whats a deadlock ?and where and when does it happen??and how to rectify it? Posted: Aug 19, 2002 6:00 AM
Reply to this message Reply
Hi Senthil,

Before we come across the meaning of Deadlock .. Well u know that a printer is a shared device. When one job is printed the other's cannot print it unless & untill it completes.

Same way when we have a thread which calls on a sycrhonized method. We say it enters the monitor. Unless & untill the Thread completes the execution no other thread can enter the monitor( I mean call the method)

U will be having many resources like the printer to be shared.

Now assume that u have two resources A & B, U also have two threads X & Y. X calls on a synchronized method & enters the monitor A which is holding the resource A. Just after that Thread Y calls another synchronized method which enters another monitor B which is holding the resource B.

Hope ur clear with this. Now we have a stituation where the both the threads have entered the monitor. Now Thread A needs to make use of the resuorce which is presently occupied by Thread B. So it waits for Thread B to come out of the monitor. Thread B which cannot complete the task bcoz it needs the resource which is occupied by Thread A. So it also waits.

Both the threads are in wait state. This waiting will never get over. This is called DEAD LOCK

There is no solution for Dead Lock, while coding the programmer has to carefully handle the code in such a way that deadlock doesn't exits.

Hope ur clear with the explanation

Cheeeeeeeeeeers

Keshav

Flat View: This topic has 2 replies on 1 page
Topic: portal framework, etc Previous Topic   Next Topic Topic: ImageFormatException

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use