File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

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() {
catch(Exception e){}
public static void main(String args[])
s t1=new s();
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
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

Sun Certified Programmer for the Java� 2 Platform

Hades Pan
Ranch Hand

Joined: Nov 25, 2001
Posts: 106
I got it thanks a lot~~!
I agree. Here's the link:
subject: The quession for Thread.sleep(times)
jQuery in Action, 3rd edition