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
Write steps of retrieving data using ado.net?
I am selected interview for computer sc.please give me some information how many types question asked in interview.my id is sumanadas10@gmail.com
Explain the concept of segmentaion.
What is the difference between a .PST file and a .OST file?
how many protocols are available and what are they?
Key difference between ip10 and ip20 of ceragon equipment?
I have Job A and Job B in jcl. I want to trigger Job B from Job A. Please advise.
Write a C/C++ program that connects to a MySQL server and checks if the InnoDB plug-in is installed on it. If so, your program should print the total number of disk writes by MySQL.
hai im going to face ibps SO IT officers grade 1 interview. if anyone had an idea plz tel me expected and experienced questions and mail to anusha_k_anu@yahoo.com
I have attended offcampus conducted by polaris chennai.And i have cleared all rounds on 10th June 2014.They collected all my marksheet xerox and address proof and said that they will send me offer letter in 3 days.. But more than 15days passed but still i didnt receive any information. I am lot depend on this offer... so when can i expect offer letter?? will they surely send me offer letter?
How many of 14 digit numbers we can make with 1,2,3,4,5 that are divisible by 4. Repetitions allowed.
i have an interview in Qatar Petroleum. So please provide the all details abt safety management
what are the main points to be included in our introduction when asked in hr...??
WAP in Java to print the format: ABC BCD CDE EFG
what is the difference between VARCHAR and VARCHAR2?