• 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

Thread

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The correct answer to the following Q is d). Should it not be e)?
What is the result of compiling and executing the following Java class:
public class ThreadTest extends Thread {
public void run() {
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}

public static void main(String args []) {
(new ThreadTest()).start();
}
}

a) Compilation will fail in the method main.
b) Compilation will fail in the method run.
c) A warning will be generated for method run.
d) The string "In run" will be printed to standard out.
e) Both strings will be printed to standard out.
f) Nothing will happen.
Select the most appropriate answer.
 
Ranch Hand
Posts: 1492
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Parimala,
Only the first print will happen because the thread is then suspending itself. It can only be resumed by calling the resume method. Since it is suspended that is impossible!
Regards,
Manfred.
 
Ranch Hand
Posts: 79
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Exactly, only if another thread calls resume() on this thread can it resume again and print the second line to std output.
Nandini
 
Ranch Hand
Posts: 135
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey
guys don't u think resume and suspend are DEPRECATED so not on exam??
regards
denish
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Quote from the book Complete Java 2 Certification Study Guide:
The suspend() and resume() methods are deprecated as of the Java 2 release and have no place in the Java 2 version of the Certification Exam...
Steffen
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic