sleep method in thread java program

Ads
 

sleep method in thread java program

How can we use sleep method in thread ?

View Answers

June 11, 2012 at 7:04 PM

public class test {
    public static void main(String [] args){
                  String str[] ={"Delhi","Bihar","Goa"
                                 ,"Pune" ,"Mumbai"};

                  for (int i = 0; i <str.length; i++) {
                    try {
                     System.out.println(str[i]);
                     Thread.sleep(5000);

                 } catch (InterruptedException e) {
                }
              }
            } 
          }

Output

Delhi
Bihar
Goa
Pune
mumbai

Description:- In this thread example ,we have used sleep method. we are passing some interval to the sleep method .After that interval thread will awake.

Ads









Related Tutorials/Questions & Answers:
sleep method in thread java program
sleep method in thread java program  How can we use sleep method... Description:- In this thread example ,we have used sleep method. we are passing some interval to the sleep method .After that interval thread will awake
Java Thread : sleep() method
Java Thread : sleep() method In this section we are going to describe sleep() method with example in java thread. sleep() method : Suppose you want to stop your thread for a specific time period, you can use sleep() method
Advertisements
java sleep in main method
java sleep in main method  Hi, How to write Java program for sleeping in the main method? I want Java program to have sleep in main method. Try to share me the code examples. Thanks
java sleep in main method
java sleep in main method  Hi, How to write Java program for sleeping in the main method? I want Java program to have sleep in main method. Try to share me the code examples. Thanks
java thread program
java thread program  write a java program to find out the current running thread in a java program   public class RunningThreads{ public...() + ":" + group.getClass()+"]"); int count = group.activeCount(); Thread[] threads
java thread program
java thread program  write a java program to find out all the current running thread in a java program   public class RunningThreads...() + ":" + group.getClass()+"]"); int count = group.activeCount(); Thread[] threads
Java Thread : toString() method
Java Thread : toString() method In this section we are going to describe toString() method with example in java thread. toString() method : If you want... and thread group. Example :In this example we are using toString() method
Java Thread : setDaemon() method
Java Thread : setDaemon() method In this section we are going to describe setDaemon() method with example in java thread. Daemon Thread  : In Java.... public final void setDaemon(boolean on) : This method sets user thread either
Java Thread : isAlive() method
Java Thread : isAlive() method In this tutorial you will learn how to use isAlive() method in java thread. isAlive() method : When you are running many... of your thread dead. This can be checked by using method Thread.isAlive(). boolean
Java Thread : run() method
Java Thread : run() method In this section we are going to describe run() method with example in java thread. Thread run() : All the execution code...() : By extending the Thread class, run() method is overridden and put all
Java Thread : isDaemon() method
Java Thread : isDaemon() method In this section we are going to describe isDaemon() method with example in java thread. Daemon Thread  : In Java Thread, daemon threads are used to perform services for user threads. You can
Java Thread : yield() method
Java Thread : yield() method In this section we are going to describe yield() method with example in java thread. yield() Method: When you want to stop...() method of Thread. public static void yield() - This method pauses
Java Thread : stop() method
Java Thread : stop() method In this section we are going to describe stop() method with example in java thread. stop() method : Java thread provides method stop to stop any running thread. It is deprecated  as it causes
Method overloading in java program
Method overloading in java program  How can we use method overloading in java program?   Method overloading:?In method overloading methods have same name but different type of parameters. Here is an example of method
Java Method Synchronized
Java Method Synchronized       The Java language Program supports multi threads. The synchronized is a keyword used in Java ensures that only one Java thread execute an object's
java program on recursive method
java program on recursive method  in how many ways can you make change for one dollar(100 cents) using pennies(1-cent coins), nickels(5 cents), dimes(10 cents),and quarter(25 cents)? the coins must add up to the exact total
is having any method same behavior of Single thread model in java?
is having any method same behavior of Single thread model in java?  is having any method same behavior of Single thread model in java
is having any method same behavior of Single thread model in java?
is having any method same behavior of Single thread model in java?  is having any method same behavior of Single thread model in java
is having any method same behavior of Single thread model in java?
is having any method same behavior of Single thread model in java?  is having any method same behavior of Single thread model in java
is having any method same behavior of Single thread model in java?
is having any method same behavior of Single thread model in java?  is having any method same behavior of Single thread model in java
Java Exception Thread
independently in program. Method in Object  and Thread Class... to Overcome this Thread Exception in Java Program In the preceding code, we... Java Exception Thread     
Java Thread setName() Example
Java Thread setName() Example In this section we are going to describe setName() method with example in java thread. Thread setName() :  Suppose,  you want to change name of your thread so for that java thread provides
thread program for calculator implementation
thread program for calculator implementation  Hi i'm prem i need calculator progrm in java that are implemented by Thread interface.....pls strong text
Java Thread getStackTrace Example
Java Thread getStackTrace Example This section explains use of getStackTrace() method  in java Thread. Thread getStackTrace() : It returns an array... as the stack dump of the given thread. This method provides the array of stack trace
Java Thread IsInterrupt
Java Thread IsInterrupt In this section we are going to describe isInterrupt() method with example in java thread. Thread IsInterrupt : If you want to check that your thread is interrupted or not, Thread class provide you method
Java :Thread Join
Java :Thread Join In this tutorial you will see how to use join method in java thread. join() method - join method waits until the thread die. If we... method of thread. public class ThreadJoin implements Runnable { Thread thread
Java Thread
. For putting your thread into wait state you can call method wait(),sleep...Java Thread In this tutorial we will discuss about Java Thread. Java Thread : A thread is light weight java program.JVM permits you to have multiple
java Thread
java Thread  what is purpose of Thread
JAVA Method Wait
JAVA Method Wait       The Wait method in Java hold the thread to release the lock till the thread hold the object. The most important point is to be remember that wait method
I want only one method goes to sleep but both method goes to sleep together
I want only one method goes to sleep but both method goes to sleep... want like a sleep() or any other method should be invoked between User's turn and Computer's turn. But when i call Sleep() before cpuPlay() method or after
I want only one method goes to sleep but both method goes to sleep together
I want only one method goes to sleep but both method goes to sleep... want like a sleep() or any other method should be invoked between User's turn and Computer's turn. But when i call Sleep() before cpuPlay() method or after

Ads