aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes The quession for Thread.sleep(times) 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 "The quession for Thread.sleep(times)" Watch "The quession for Thread.sleep(times)" New topic
Author

The quession for Thread.sleep(times)

Hades Pan
Ranch Hand

Joined: Nov 25, 2001
Posts: 106
class s extends Thread{int j=0;
public void run() {
try{Thread.sleep(5000);}
catch(Exception e){}
j=100;
}
public static void main(String args[])
{
s t1=new s();
t1.start();
System.out.println(t1.j);
}
}
what you have to do to ensure that 'j' will print 100
a you have make t1 as Daemon Thread
b You have join the t1 to main
c You have to suspend the main when the thread starts and resume it after
d the value of 'j' is set to 100
e You have to interrupt the main thread
Ans is "b", Why? and why not "c"
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Hades
Suspend and resume are both deprecated methods. Using join you can ensure the main thread does not continue running until after the t1 has completed.
hope that helps

------------------
Dave
Sun Certified Programmer for the Java� 2 Platform


Dave
Hades Pan
Ranch Hand

Joined: Nov 25, 2001
Posts: 106
I got it thanks a lot~~!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: The quession for Thread.sleep(times)