This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about Threads

 
Nithya Natarajan
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rob Ross
Bartender
Posts: 2205
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sam Cooper
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7610
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks again for the immediate reply!
Now I'm clear about this.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic