This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Threads

 
Smitha Ballikar
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is part of the code for an application that will run two time consuming processes in two Threads. We want to be sure that all threads get a chance to run. Which statement at line 9 will accomplish this?

Here answer is A,D
THe answer is not C.The reason given is because the class does not extend thread . Does that mean that if a class does not extend thread and implements runnable we cannot use yield() directly.I thought its because its static..
What is the concept here??

Cheers
Smitha
[ August 24, 2005: Message edited by: Barry Gaunt ]
 
vijaya bacina
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
when u use yield();
the call to the method is implicitly like
this.yeild();
and runnable interface has no methods like yeild() and ur class didn't provide any method by name yeild()
so u get a compiler error says the method yeild is undefined for Testxx class
 
Smitha Ballikar
Ranch Hand
Posts: 99
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi vijaya,

Thanks for all your answers!!



Regards
Smitha
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose it had Thread.sleep(1000); then why this method call wd not help in ensuring the threads get a chance to run??
 
raghu babu
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sleep method should be between a try-catch block as it throws InterruptedException. But, the options given doesn't show that
sleep is coded between try-catch block.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic