sleep method in thread java program

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.









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 Thread
Java Thread sleep() is a static method. It sleeps the thread for the given time in milliseconds. It is used to delay the thread. It is used in Applet or GUI programming for animation Java Sleep Thread Example public class
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
example of sleep and wait method
example of sleep and wait method  write a program to use the sleep and wait method of thread class
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 : 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 Thread, daemon threads are used to perform services for user threads. You can
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().ADS
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... public void run() : By extending the Thread class, run() method is overridden
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 : 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...() method to display info of thread. public class ThreadToString implements
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. public class ThreadYield implements Runnable { Thread thread
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
PHP Sleep Wakeup Method
purpose. The serialize method checks every program whether it has a magic method __sleep or not. If so, then the function execute that method prior to any other... any resources that the object may have. PHP Sleep and Wakeup Method Example
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
Thread method
Thread method  What is the purpose of the wait(), notify(), and notifyAll() methods
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
_TO_REPLACE_2 5)Thread can run independently in program. Method in Object ...); ^ How to Overcome this Thread Exception in Java Program... Java Exception Thread     
Java thread
Java thread  What is the difference between wait() and sleep method
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 state
Java thread state  Difference between sleep and suspend
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
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
Java Thread Context
classloader to set a thread using Thread.setContextClassLoader() method... Thread Context       The Thread Context is required by the current thread from the group
Java thread
Java thread  What invokes a thread's run() method
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 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... : In this tutorial we are using join method of thread. public class ThreadJoin
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
a multithreaded program by creating a subclass of Thread
a multithreaded program by creating a subclass of Thread  I want... this OUTPUT thread1: Java thread1: is thread2: Java thread1: an thread2.... but mine not display like that output why ? My output : thread1: Java thread2
Thread in java
Thread in java  which method will defined in thread class
Java Thread Priority
() method. Java Thread Priority Example public class priority implements... Java Threads run with some priority There are Three types of Java Thread...++) System.out.println(x + " This is thread " + Thread.currentThread
method overloading in c program
method overloading in c program  how is method overloading in C program is different from C++ program
Create Thread by Extending Thread
by extending Thread class in java. Extending Thread : You can create thread...() method, initialize the thread in its constructors. For beginning the execution...(); thread2.start(); try { Thread.currentThread(); /* The sleep() method
Java Thread
call method wait(),sleep(), or suspend(). Dead : A thread reached in dead...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
Extending thread - Java Beginners
visit to : http://www.roseindia.net/java/thread/index.shtml Thanks...Extending thread  what is a thread & give me the programm of exeucte the thread   Hi friend, Thread : A thread is a lightweight
Java Thread setName
Java Thread setName() method sets the new name to each Thread. It is used in both Thread class and Runnable interface. Name is also set by the string data used in the constructor. Java Thread setName Example public class
Java Current Thread
Java Current Thread In this tutorial, we are using Thread.currentThread() method to find the current thread name. Thread.currentThread() : Thread class provides method to display the current running thread. It is static Thread
Java Thread destroy
Java Thread destroy In this tutorial, we are using Thread.destroy() method... method to destroy the thread. In general, Thread.destroy() is dangerous...() : This method destroy your thread without any cleanup. The locked monitor remains lock
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
Thread
instance the thread is in this state but before the start() method invocation... after the invoking of start() method but a thread can return to this state after... ? A thread can be considered dead when its run() method completes. If any thread comes
Java Programming Question
Java Programming Question  write a program in java to show thread working with sleep and wait method   Hi Friend, Please visit the following links: Wait Method Sleep Method Thanks
java Thread
java Thread  what is purpose of Thread

Ads