Results 1 to 2 of 2

Thread: Sleep in thread

  1. #1
    jithan is offline Member
    Join Date
    Jun 2008
    Posts
    39
    Rep Power
    0

    Default Sleep in thread

    hello friends,

    i have to sleep a particular thread...... how to do that? i have given below in my pgm...... if i sleep my particular thread all the threads has slept...... what i have to do for sleep a particular thread .......


    class RowlevelLocking extends Thread implements Runnable
    {
    Thread x,y;
    RowlevelLocking()
    {
    x = new Thread(this,"a");
    y = new Thread(this,"b");
    x.start();
    y.start();
    }
    public static void main(String arg[])
    {
    new RowlevelLocking();
    }

    public void run()
    {
    while(true)
    {
    display();
    }
    }
    private void display()
    {
    System.out.println("welcome.......");
    x.sleep(1000);
    }

    }
    here if i sleep the x thread the y thread also sleep............... what i have to do a sleep a separate thread.............

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    16,559
    Rep Power
    23

    Default

    Before calling sleep, test a variable to see if its the thread that is supposed to be sleeping. Thread has methods to get the currentThread.
    YOu could pass something in the constructor to say if the thread is to sleep or not. For example if thread name = "a" then sleep.

Similar Threads

  1. How to use sleep method of the Thread class
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-09-2008, 06:42 PM
  2. Can't get my thread to sleep!
    By jamesfrize in forum New To Java
    Replies: 2
    Last Post: 03-25-2008, 05:14 AM
  3. Replies: 0
    Last Post: 01-28-2008, 07:02 AM
  4. How to use the sleep and thread?
    By jiuhu in forum Java Applets
    Replies: 4
    Last Post: 08-07-2007, 02:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •