Can any1 say how this prog logic works... i am weak in thread
concept...pls explain step by step
Answer / 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 |
Q1. What do you mean by VPN(virtual private network)? Q2. What do you mean by switching and what are it's type? @3. What do you mean by ATM switching?
where is interrupt vector table is located??
char *a[2]; int const *p; int *const p; struct new { int a;int b; *var[5] (struct new)} Describe the statements in the above given construct ?
what are active and passive components
how 2 write a program of this pattern usin for loop?? 1 2 3 4 5 6 7 8 9 10
PLEASE SUGGEST THE BALLY PLACEMENT PAPER PATTERN ABOUT WRITTEN TEST,INTERVIEW,HR.ITS URGENT. AS BALLY IS GOING TO VISIT OUR CAMPUS.
what is the differences between software engineering and other engineering disciplines.
Discuss about WAP architecture in detail.
2 ships are wardroom light house one side at 30 degree and other ship other side at 45 degree. If light house has 100 m, find distance of boat from light house. and also find distance of each boat from light house
what is the difference between primary key and foreign key?
Some question are asked from computers also. How we calculate sum in Excel? can we find cube root in Excel if yes , how? If i want to send excel sheet to 10 different person, how i can send it ( don`t tell me by mailing) condition given by interviewer.If A=.03rs(tsqr), value of r increase by 50%, s by 30% & t decrease by 20%. find value of A. If two coins having dia 25 & 16 they are rotate in their axis , Coin having dia 25 reach a point at x per sec, in how many min coin having dia 16 reach that place, Both are rotating in same direction.
Please derive the formula for the area of a circle.