• 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

I need your help about a Thread question.(scjp03-Q56)

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is displayed when the following piece of code is executed.
1. class Test extends Thread {
2. public void run() {
3. System.out.print("1 ");
4. yield();
5. System.out.print("2 ");
6. suspend();
7. System.out.print("3 ");
8. resume();
9. System.out.print("4 ");
10. }
11 public static void main(String []args) {
12. Test t = new Test();
13. t.start();
14. }
15. }
a. Nothing, this is not a valid way to create and start a thread.
b. 1 2
c. 1 2 3
d. 1

the given ans is B which have been proved right.but I am not so clear with ans ,could somebody give me a explaination about it .
pls,I need your help!!
 
Enthuware Software Support
Posts: 4810
52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Once you call suspend() on a thread, that thread doesn't run anymore untill sombody calls resume() on that thread. Here, the thread itself is calling suspend on itself and so stops running. Now, if it is not running, it cannot execute the remaining statements and hence cannot resume() itself. And there is nobody else to start it up again!
HTH,
Paul.
------------------
SCJP2, SCWCD Resources, Free Question A Day, Mock Exam Results and More!
www.jdiscuss.com
Get Certified, Guaranteed!
JQPlus - For SCJP2
JWebPlus - For SCWCD
JDevPlus - For SCJD
 
reply
    Bookmark Topic Watch Topic
  • New Topic