Can any1 say how this prog logic works... i am weak in thread
concept...pls explain step by step



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

Post New Answer

More Engineering AllOther Interview Questions

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?

0 Answers  


The old welding machine use electro- -magnetic winding to step up the current for welding rods,what is new principle inside the welding

0 Answers  


Please send the questions asked at HLL??

1 Answers   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

0 Answers   IBM,


what is c dot

0 Answers  






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?

3 Answers   Reddy Labs,


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

0 Answers  


Define function ? Explain arguments in functions ?

0 Answers   Geometric Software,


what is your career objective?

0 Answers   Infosys,


how to increase the water ring vacuum pump efficiency?

0 Answers  


HTML tag for bulleted list is--------------

0 Answers  


what are the artifacts in coding phase in SDLC????

0 Answers  


Categories
  • Civil Engineering Interview Questions Civil Engineering (5085)
  • Mechanical Engineering Interview Questions Mechanical Engineering (4451)
  • Electrical Engineering Interview Questions Electrical Engineering (16632)
  • Electronics Communications Interview Questions Electronics Communications (3918)
  • Chemical Engineering Interview Questions Chemical Engineering (1095)
  • Aeronautical Engineering Interview Questions Aeronautical Engineering (239)
  • Bio Engineering Interview Questions Bio Engineering (96)
  • Metallurgy Interview Questions Metallurgy (361)
  • Industrial Engineering Interview Questions Industrial Engineering (259)
  • Instrumentation Interview Questions Instrumentation (3014)
  • Automobile Engineering Interview Questions Automobile Engineering (332)
  • Mechatronics Engineering Interview Questions Mechatronics Engineering (97)
  • Marine Engineering Interview Questions Marine Engineering (124)
  • Power Plant Engineering Interview Questions Power Plant Engineering (172)
  • Textile Engineering Interview Questions Textile Engineering (575)
  • Production Engineering Interview Questions Production Engineering (25)
  • Satellite Systems Engineering Interview Questions Satellite Systems Engineering (106)
  • Engineering AllOther Interview Questions Engineering AllOther (1379)