• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to make a thread sleep

 
Venkat Ramsimha
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Give it some warm milk?

Mark
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Mark Spritzler:
Give it some warm milk?

Iterating through a large array of boolean values works for me.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic