• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

how to make a thread sleep

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Give it some warm milk?

Mark
 
marc weber
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
I am Arthur, King of the Britons. And this is a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic