• 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

tell me

 
Ranch Hand
Posts: 641
  • 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:

class Test extends Thread{
public void run(){
System.out.println("1");
yield();
System.out.println(2");
suspend();
System.out.println("3");
resume();
System.out.println("4");
}

public static void main(String []args){
Test t = new Test();
t.start();
}
what do you think the output should be ?
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
well, the methods resume() and suspend() have been deprecated as in java 2. (i can confirm for jdk 1.2.2)
so there is no point in using these methods as you will not be tested on these methods.
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by raghav mathur:
What is displayed when the following piece of code is executed:
...
what do you think the output should be ?


It looks like 1 2 to me. Calling yield will allow any other threads that are ready to run to execute, but this thread will eventually get the processor. When you call suspend, however (which is deprecated), the thread will leave the running state. As no other object makes a call to resume on that thread, it will never make its way back to the running state. Of course, it will never terminate, either. It will simply hang in a suspended state indefinitely. Therefore, this application will never terminate.
Hope that helps,
Corey
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
raghav
Two things...
1. Did you run the code and find out what it prints? Or if it will even compile?
2. When you post a topic it helps the readers of the forum to put some sort of meanngful title on the topic. 'Tell Me' doen't give anyone a clue as to what the topic is!!

just pet peeve of mine.
 
Raghav Mathur
Ranch Hand
Posts: 641
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dave Vick:
raghav
Two things...
1. Did you run the code and find out what it prints? Or if it will even compile?
2. When you post a topic it helps the readers of the forum to put some sort of meanngful title on the topic. 'Tell Me' doen't give anyone a clue as to what the topic is!!

just pet peeve of mine.



sorry about the subject .
the question has been taken from jxam . According to the author the answer should be 1,2 .
how ?
thanks .
 
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic