• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Threads

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i guess the problem may bewith wait() and notifyall() methomk
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The code called bm.wait() when it didn't own the lock on bm.

This throws an IllegalMonitorStateException.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Divakar you must use wait nad notify methods in Synchronized method or synchronized block only otherwise it will be a error
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic