hi! When i run the following code, the output is:
entered in run
entered in run
end of run
end of run
As the run() method is synchronized and the sleep() method doesn't release the lock so the second
thread shouldn't get a chance to enter in run(). But her as the output shows on calling the sleep() the second thread enters in the run method and executes //1. Why is it so? Can u help me pl?
thanks.
ashok.
______
class TestThread extends Thread {
public synchronized void run() {
System.out.println("entered in run"); //1
try {
sleep(1000);
} catch(InterruptedException ie) {}
System.out.println("end of run"); //2
}
public static void main(
String args[]) {
new TestThread().start();
new TestThread().start();
}
}
________