File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Threads" Watch "Threads" New topic
Author

Threads

deshdeep divakar
Ranch Hand

Joined: Apr 19, 2004
Posts: 91
What will happen when you attempt to compile and run the following code?
public class BriarMill extends Thread{
public static void main(String argv[]){
BriarMill bm = new BriarMill();
bm.go();
}
public void go(){
start();
}
public void payBill(){
try{
wait();
}catch(InterruptedException ie){}
System.out.println("done");

}
public void run(){
payBill();
notifyAll();
}

}



1) Compilation but runtime error.
2) Compilation and output of done at runtime
3) Compilation but no output at runtime, the program will run and wait with no output.
4) Compile time error

According to me the answer wuld be 4,but stated wrong plz guide me to the
Appropriate answer.


"Do not be afraid of going slow, be afraid of standing still"
Parameswaran Thangavel
Ranch Hand

Joined: Mar 01, 2005
Posts: 485
i guess the problem may bewith wait() and notifyall() methomk
Mike Gershman
Ranch Hand

Joined: Mar 13, 2004
Posts: 1272
The code called bm.wait() when it didn't own the lock on bm.

This throws an IllegalMonitorStateException.


Mike Gershman
SCJP 1.4, SCWCD in process
nagaraj reddy
Ranch Hand

Joined: Feb 21, 2005
Posts: 43
Divakar you must use wait nad notify methods in Synchronized method or synchronized block only otherwise it will be a error
 
 
subject: Threads
 
Similar Threads
Wait() doubt
Two's Complement
Mock exam question
quest no static
constructor