-
April 1st, 2013, 11:27 PM
#1
wait/notify
Code:
public class Airport {
public static void main(String[] args) throws InterruptedException {
passenger p = new passenger();
p.start();
synchronized (p) {
System.out.println("passenger is waiting for the plane ");
p.wait(6000000);
System.out.println("passenger notify");
}
System.out.println("after "+p.total+" time!");
}
}
class passenger extends Thread {
int total = 0;
public void run() {
synchronized (this) {
System.out.println("wait.... ");
/*try {
wait();
} catch (InterruptedException e) {}*/
for (int i = 0; i <= 10; i++)
total = i;
if ( total==10){
System.out.println("passenger is given notification call");
//notify();
}
}
}
}
1-This program must wait for 6000 seconds, But it does not!! Why?
2-In line 7, Is this main thread that must wait for 6000 seconds?Or thread who runs run method?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|