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 does the interviewer mean by saying "have a good life " cheerfully at the end of an HR interview??? is this positive or negative sign to be selected?
The old welding machine use electro- -magnetic winding to step up the current for welding rods,what is new principle inside the welding
Please send the questions asked at HLL??
briefly explain about your project? please tell me about this answer . my current project is ERP domain web based application.please please help me
what is c dot
One bag contains 4 white balls and 3 black balls, and second bag contains 3 white balls and 5 black balls. One ball is drawn from the first bag and placed unseen in the second bag. What is the probability that a ball now drawn from second bag is black?
hello sir, i'm persuing my B.tech final year in textile chemistry and have a diploma in electronics and communication...interviewer ask why you should adopt textile chemistry from electronics and communication....please give me the best answer... thank you
Define function ? Explain arguments in functions ?
what is your career objective?
how to increase the water ring vacuum pump efficiency?
HTML tag for bulleted list is--------------
what are the artifacts in coding phase in SDLC????