This week's giveaways are in the MongoDB and Jobs Discussion forums. We're giving away four copies of Mongo DB Applied Patterns and 4 resume reviews from Five Year Itch and have the authors/reps on-line! See this thread and this one for details.
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 ?
Raghav.
mark stone
Ranch Hand
Joined: Dec 18, 2001
Posts: 417
posted
0
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
Joined: Dec 20, 2001
Posts: 3271
posted
0
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
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.
Dave
Raghav Mathur
Ranch Hand
Joined: Jan 12, 2001
Posts: 639
posted
0
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 .