• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

thread mock question  RSS feed

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider that following code is declared in BussyThread.java file

public class BussyThread extends Thread{
public void run(){
for(int i=0;i<10; i++){
i=i-1;
}//end of for loop
}//end of run()
public static void main(String args[]){
BussyThread b1=new BussyThread();
BussyThread b2=new BussyThread();
b1.start();
b2.start();
}
}//end of class

Above class will start two threads b1 and b2. Select True statements for above class.

A. Only b1 thread will get chance to run
B. Only b2 thread will get chance to run
C. Both thread will get chance to run sharing CPU time
D. Neither of the thread will be able to run.

the answer is A and B. why not C?
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vikas,

The execution depends on the implementation of the JVM. As result, either A or B or C is correct.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!