Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Write steps of retrieving data using ado.net?

2391


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

1867


Explain the concept of segmentaion.

2167


What is the difference between a .PST file and a .OST file?

4072


how many protocols are available and what are they?

2410


Key difference between ip10 and ip20 of ceragon equipment?

5239


I have Job A and Job B in jcl. I want to trigger Job B from Job A. Please advise.

2040


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.

1774


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

1682


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?

2860


How many of 14 digit numbers we can make with 1,2,3,4,5 that are divisible by 4. Repetitions allowed.

2741


i have an interview in Qatar Petroleum. So please provide the all details abt safety management

2071


what are the main points to be included in our introduction when asked in hr...??

2008


WAP in Java to print the format: ABC BCD CDE EFG

2607


what is the difference between VARCHAR and VARCHAR2?

23759