Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes how to make a thread sleep 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 "how to make a thread sleep" Watch "how to make a thread sleep" New topic
Author

how to make a thread sleep

Venkat Ramsimha
Ranch Hand

Joined: Dec 28, 2004
Posts: 127
Hi Everybody

Consider the code:
class SecondThread extends Thread
{
public void run()
{
System.out.println("In the Second Thread");
}

}

class ThirdThread extends SecondThread
{
public void run()
{
System.out.println("In the third thread");
}
public static void main(String args[])
{
SecondThread st = new SecondThread();//Thread not alive
ThirdThread tt = new ThirdThread();//Thread not alive
st.start();//Thread alive
tt.start();//Thread alive
}

}

In the above program i need to make a "thread" to "sleep" so how and where to place sleep method in the above program.Also i need to know how to use
sleep method placed in the "try/catch" block


tx®ards
venkat
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Calling Thread's sleep(long) method puts the current Thread in a sleep state for the number of milliseconds specified by the long argument, after which the Thread enters the ready state. While in the sleep state, the Calling Thread's sleep(long) method puts the current Thread in a sleep state for the number of milliseconds specified by the long argument, after which the Thread enters the ready state. While in the sleep state, the Thread does not release the object lock, but it does stop using the CPU. Note that sleep() is a static method that always executes on the current Thread -- sleep() cannot be called on another Thread.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

Give it some warm milk?

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Mark Spritzler:
Give it some warm milk?

Iterating through a large array of boolean values works for me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to make a thread sleep
 
Similar Threads
Thread doubt about wait() method
Q. Methods of a dead thread.
synchronized blocks for static and non-static methods
Using wait() and notify()
Threading synchronization