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 |
tcs aptitude questions
what are nanoemulsions and how are they prepared? i want a brief outline about nanoemulsions.. is anyone of you is having any literature, can you share that? also any an idea where i can get the information?
Dear sir 1: i know about IIT & AIEEE prepration which city is best and top 1 position ? 2: Top 10 institute in INDIA for prepration to IIT & AIEEE plz get me detail knowldge? 3: where is better invoirnment availble for IIT & AIEEE entrance exam? 4: What diffrent between KOTA & DELHI institute and enviornment
Write steps of retrieving data using ado.net?
how much the percentile as a good percentile in elitmus.
what is advantages and disadvantages of vlan?
Why Mother Board is called Mother Board & not Father Board?
12 Answers Microsoft, Precision Infomatic, SoftStream,
i want to section engineer(signal) question paper......plz tell me how i get
why every computer should have a boot strap routine?
give me a example of an application of Low severity & high priority.
can anyone help me with an article or a few pointers on what are the industry expectations from Fresh engineers in today's market scenario
Always declare destructors to be virtual"?????? why this is so needed?????