Can any1 say how this prog logic works... i am weak in thread
concept...pls explain step by step

Answer Posted / nachiyappan

class A {

synchronized void foo(B b) {
String name = Thread.currentThread().getName();
System.out.println(name + " entered A.foo");
try {
Thread.sleep(1000);
} catch (Exception e) {
System.out.println("A Interrupted");
}
System.out.println(name + " trying to call
B.last()");
b.last();
}

synchronized void last() {
System.out.println("Inside A.last");
}
}

class B {

synchronized void bar(A a) {
String name = Thread.currentThread().getName();
System.out.println(name + " entered B.bar");
try {
Thread.sleep(1000);
} catch (Exception e) {
System.out.println("B Interrupted");
}
System.out.println(name + " trying to call
A.last()");
a.last();

}
synchronized void last() {
System.out.println("Inside A.last");
}
}

class Deadlock implements Runnable {

A a = new A();
B b = new B();

Deadlock() {
Thread.currentThread().setName("MainThread");
Thread t = new Thread(this, "RacingThread");
t.start();
a.foo(b); // get lock on a in this thread.
System.out.println("Back in main thread");
}

public void run() {
b.bar(a); // get lock on b in other thread.
System.out.println("Back in other thread");
}

public static void main(String args[]) {
new Deadlock();
}
}

Is This Answer Correct ?    0 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

i have applied for junior engg. signal II please send me questions papers for it

1481


Hi dost here Alok Kumar please send question pattern for NIC at godinall.kumar1@gmail.com or alok.iitb07@gmail.com

1411


How we can find out face expression ,what approach should be followed (like skin detection) ?

1412


why view is created in database

1219


why need of new operator in java why not in c++

1412






Let an denote the number of bit strings of length n that do not have two consecutive zeroes. Find a recurrence relation for the number of bit strings of length n that do not have two consecutive zeroes. Hence find a4.

1870


what is static identifier in c language?

1694


how to hack email id & passward

1678


What is the allowable load carrying capacity of a circular column section of 400 mm diameter reinforced with 6x25 mm diameter bars adequately tied with spirals? Consider concrete of grade M25 and steel of grade Fe 415.

1618


is it possible to get u.s visa with 55% in b-tech and 15 backlogs

1538


hey..... anybody here from CG? i m from CG n have been selected in the written xam sbi(clerical).interview date is 5/5/2010. answer me if anybody is there 4m CG

1356


plz plz help me "how can i face dell varcent round"....? plzzzzzzzz help me friends.....?

1539


if u r using bugzilla then it generates automatic bugids,while testing uhave got a bug then bug is represented through a bug id say bug1, then bug is assigned to developer he fixes a bug ,say the bug is fixed no error is got later after few regression cycles u have got the same bug but the bug is represented by diff id say bug2,tell me how do i come to know that it is the same bug that had occured previously but now it is represented by diff id

1421


Write a test case plan for a typical banking application which involves functionalities like Balance enquiry, deposit, fund transfer etc. Make your assumptions and mention the same in your answer sheet.

1548


An inversion is an array of numbers is any pair (i,j) such that iA[j]. What is the average number of inversions in an array of n distinct numbers? plz GIVE ME SOLUTION

1435