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

tell me

 
Raghav Mathur
Ranch Hand
Posts: 641
  • 0
  • Mark post as helpful
  • send pies
  • 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 ?
 
mark stone
Ranch Hand
Posts: 417
  • 0
  • Mark post as helpful
  • send pies
  • 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.
 
Corey McGlone
Ranch Hand
Posts: 3271
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Dave Vick
Ranch Hand
Posts: 3244
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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 .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic