• 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

Question about Threads

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks again for the immediate reply!
Now I'm clear about this.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic