• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Threads

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q) Animation Applet
There is a single thread animC derived from java.awt.Canvas
which holds the animation data. There is a single Thread, animT which uses this data to create a new image for the next animation frame and calls the following code
synchronised void waitforpaint(){
painted = false;
repaint();
while(!painted){
try{ wait();}
catch(InterruptedException x){}
}
}
The paint method in animC executes the following code after the new animation frame has been shown
synchronised (this)
{
painted = true;
notify();
}
After animT has entered waitforpaint and before the paint method has been executed which of the following is true
a) Other threads cannot modify data in the animC object
b) Other threads can only modify data in the animC object using synchronised methods
c) Other threads can modify data in the animC object using synchronised or unsynchronised methods
d) If the animT Thread is interrupted, it will exit the waitforpaint method
The answer is c.
I am a bit confused can u pls explain me why the answer is so.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic