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 |
what is a pointer in c language?
Do you have any tips for using 3G phones?
Why do you want to work here
hi... i just want to know that how could join the AAI with an B.E back ground??? please help me out.
0 Answers AAI Airports Authority Of India,
can i knw what are we supposed to read for the coming oces/dgfs 2009 exam?what kind of book are we supposed to study?
difference between a for loop and a while loop? what are its uses in c language?
how the aeroplane protected from the lightening?
What is the difference between Huawei 5700 switch and 5300 switch?
PLZ SOMEONE TELL ME WHICH TYPE OF QUESTIONS IS ASKED IN HLL(Hindustan latex ltd.)mangmt trainee entrance exam?
System Not Getting Shut down Through Software Auttomatically It Will Restart wat is the Problem?
what is the difference between C and C++? what is the difference between scanf and gets? what is mean by extern what is the use of it? what will happen if i say delete this> Difference between C structure and C++ structure? What is the difference between overloading and overridding? Explain the need for "virtual Destructor" Can we have "virtual Constructors"? What is the different types of polymorphism> What is virtual functions? How to implement virtual function in "C"? What are the different types of storage classes?
PLEASE SEND ME NIC SCIENTIFIC OFFICER-2009 EXAM PATTERN AND QUESTION PAPERS