Home Answers Viewqa Java-Beginners sleep method in thread java program

 
 


Naulej kumar
sleep method in thread java program
1 Answer(s)      11 months ago
Posted in : Java Beginners

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 Pages:
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
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
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
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
Thread
;Java throw and throws Whenever we want to force an exception then we use throw... a possible exception then we use throws keyword. Point to note here is that the Java... us to handle them. We can also use throws clause on the surrounding method
Java thread
Java thread  What is the difference between wait() and sleep method
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     
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... that the object may have. PHP Sleep and Wakeup Method Example: <?php
Thread
Thread  Write a Java program to create three theads. Each thread should produce the sum of 1 to 10, 11 to 20 and 21to 30 respectively. Main thread....   Java Thread Example class ThreadExample{ static int
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 of new thread call start() method. Example : In this example we are extending
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
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
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
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
Thread Memory Usage in java - Java Beginners
://www.roseindia.net/java/thread/thread-creation.shtml   but,if I use G++ tools to compile a c++ program in a java thread, as:Runtime.getRuntime...Thread Memory Usage in java  how to get a thread's memory usage? Does
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
Green Thread - Java Beginners
of Green Thread in java. Thanks in advance...  Hi friend Green threads... the years. This is simple program of thread public class ThreadExample... thread), but VM technology has advanced significantly since version 1.1 and any
Get Current Thread
; A Thread is the independent path of execution in a program. Many thread runs concurrently with a program. Some threads are Multithread, This thread refers to two or more thread running simultaneously within a program
Java :Thread Methods
Java :Thread Methods This section explains methods of Thread class. Thread Methods : Thread class provides many method to handle different thread...) - this method is used when you want to change name of your thread. setPriority
java thread - Java Beginners
Java Thread  What is thread in Java? and how can i write a Java thread program?Thanks in advance!!  Hi friend,import javax.swing.*;import...(a); } private JPanel canvas;}class Ball extends Thread { public Ball(JPanel
Java Thread
sequential flow of control within a program. Programmer may use java thread mechanism... Java Thread       A java...;thread is a sequential path of code execution within a program. Each thread has
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 : 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
Thread in java
Thread in java  which method will defined in thread class
Java thread state
Java thread state  Difference between sleep and suspend
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 : 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 : 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
Java thread
Java thread  What invokes a thread's run() method
Thread Deadlocks - Java Tutorials
Thread Deadlock Detection in Java Thread deadlock relates to the multitasking... is possible. In other words, a situation where a thread is waiting for an object lock that holds by second thread, and this second thread is waiting for an object
Thread Priorities
;    In Java, thread scheduler can use the thread...; This is method is used to set the priority of thread.  ...; This method is used to get the priority of thread.  
Thread Priorities
;   In Java, thread scheduler can use the thread priorities...; This is method is used to set the priority of thread.  ... a Java thread is created, it inherits its priority from the thread
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
Thread Priorities
;    In Java, thread scheduler can use the thread...; This is method is used to set the priority of thread...; This method is used to get the priority of thread.  
Overview of Thread
with this program. Thread A thread is a lightweight process which exist within... within a program. Each thread has its own local variables, program counter... of a program. Threading concept is very important in Java through which we
SCJP Module-8 Question-8
;); Thread.sleep(2000); System.out.println("thread sleep"); } } Which of the following statement is correct ? (A) Print "inside main" and "thread...) Print "thread sleep" and "inside main" Answer
Thread Creation
; In Java, an object of the Thread class can represent a thread. Thread...( ) method in the subclass from the Thread class to define the code executed...( ) method on the instance of the class to make the thread eligible for running
Java thread
Java thread  Can we have run() method directly without start() method in threads
Java thread
Java thread  What method must be implemented by all threads
Thread method
Thread method  What is the purpose of the wait(), notify(), and notifyAll() methods
Java :Thread Synchronization
Java :Thread Synchronization This section explains how to use concept of synchronization in java Thread. Thread Synchronization : . Java supports multi... of program. So for the multi-threaded application, synchronization of java
Thread
Thread  Explain two ways of creating thread in java. Explain at three methods of thread class.   Java Create Thread There are two main ways of creating a thread. The first is to extend the Thread class and the second
Thread priority in java
. Example : A program how to set or get priority of thread in java. class...Thread priority in java A thread is a part or entity of a  process... concurrently. In java each and every thread has priority , priority means which
Thread
=" + i); } public static void main(string args[]) { A a = new A(); Thread t = new thread(a); t.start(); } } Is it possible to run above program with out...Thread  will this code work..? class A extends Thread { public
Java Thread Yield
Java Thread yield is a static method It works on same priority threads It makes same priority thread from running to runnable state. Then other same priority thread comes to running state from runnable state Java Yield

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.