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 ? | 1 Yes | 0 No |
Post New Answer View All Answers
how convert the spiral model to prototype model ?
can 25mm thik and 8.5x8.5 size cast iron plate can bear a weight of 250 tons if it can what would be the compostion
3. Tell me about a time when you had too many things to do and you were required to prioritize your tasks.
Explain the concept of segmentaion.
explain various object oriented programming fetures
which/why unix commands are simpler rather than complex tasks
CSS corp interview process and placement papers
in single linked list , each node contains data and address of next node. if middle of list the node is damaged/crashed then how to find where the link is failed and how to get the all the data which is stored after the crashed node?
Is there aptitute question will be asked in NIC exam ??? If yes how many questions will be asked??
program for inter process communicatin using message sharing in unix c
how to increase the water ring vacuum pump efficiency?
how will u send the idoc
please explane me clusterd and non clusterd
5S training documents
objective type quistion