GeeCON Prague 2014*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question about Threads Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question about Threads" Watch "Question about Threads" New topic
Author

Question about Threads

Nithya Natarajan
Ranch Hand

Joined: Feb 25, 2002
Posts: 30
Hello Everyone!
Thanks for the immediate response to my previous posts
I have the following code from John Hunts Mock Exam:
public class MyThread extends Thread {
public void run() {
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}

public static void main(String args []) {
(new MyThread()).start();
}
}
When I try to compile this code with jdk1.3, it gives me an error: Note:
C:\jdk1.3\Class\MyThread.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
But the answer for this question is :
The string "In run" will be printed to standard out.
Can anyone please explain the problem here.


Thanks<br />Nithya<br />Sun Certified Java 2 Programmer
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
suspend() and resume() are deprecated methods which should not be used anymore as they have a risky behavior. You can still run your program to see what the output is.


SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Rob Ross
Bartender

Joined: Jan 07, 2002
Posts: 2205
You should look again. The compiler is NOT giving you an error. It's giving you a deprecation warning. It's very different. If you compile it, this program should run and produce the output stated in the answer.
A deprecation warning occurs when the authors of an API have decided to stop supporting that method. In some future version of the API, that method might no longer be available, so they're warning you about it now so you can adjust your programs to no longer use the method. Think of it as approaching a Yellow traffic light (in the USA we have green = go, yellow = prepare to stop, red = stop). So instead of just removing the method, they warn you that the method is going to be removed someday.
If you run this program, you should see the text "In run" print out, then the program will seem frozen. The thread has suspended itself and will not proceed until resumed by another thread. Therefore, your thread will just stay "frozen" until you force-quit the application.


Rob
SCJP 1.4
Sam Cooper
Greenhorn

Joined: Feb 21, 2002
Posts: 14
Look at the java api, there is good article there on the Deprecated suspend and resume.
Follow this

Deprecated suspend and resume
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
Off topic
(in the USA we have green = go, yellow = prepare to stop, red = stop)
Yeah sometimes I feel like "up here" it is more like green=go, yellow=go, red=go_anyway)
Nithya Natarajan
Ranch Hand

Joined: Feb 25, 2002
Posts: 30
Thanks again for the immediate reply!
Now I'm clear about this.
 
GeeCON Prague 2014
 
subject: Question about Threads