aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes tell me Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "tell me " Watch "tell me " New topic
Author

tell me

Raghav Mathur
Ranch Hand

Joined: Jan 12, 2001
Posts: 641
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
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
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


SCJP Tipline, etc.
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
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: 641
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 agree. Here's the link: http://aspose.com/file-tools
 
subject: tell me