Results 1 to 3 of 3

Thread: Dead threads

  1. #1
    Onra is offline Member
    Join Date
    Nov 2009
    Posts
    41
    Rep Power
    0

    Default Dead threads

    Hello,

    I have a question about dead threads in Java. If their run method has ended, but they're still referenced, can I restart them? Or do I have to create a new one?

  2. #2
    uoty is offline Member
    Join Date
    Dec 2010
    Location
    Nova Scotia, Canada
    Posts
    2
    Rep Power
    0

    Default

    Hey,
    I'm pretty sure you have to start a new one or you get an IllegalThreadStateException.

  3. #3
    Dennis's Avatar
    Dennis is offline Member
    Join Date
    May 2010
    Posts
    83
    Rep Power
    0

    Default

    When a thread is ended you need to create a new one.
    But if you have a runnable set, you can use that one again.

    Java Code:
    public class theClass implements Runnable
    {
     public theClass()
     {
      Thread t = new Thread(this);
      t.start();
      while(t.isAlive());
      t = new Thread(this);
      t.start();
     }
    
     public void run()
     {
      // Here inside the Thread
     }
    
     public static void main(String... args)
     {
      new theClass();
     }
    }
    Last edited by Dennis; 12-19-2010 at 01:28 PM.

Similar Threads

  1. Restarting dead threads
    By DC200 in forum Threads and Synchronization
    Replies: 3
    Last Post: 12-03-2010, 10:09 PM
  2. Threads
    By Tanuck in forum New To Java
    Replies: 5
    Last Post: 09-21-2010, 02:44 AM
  3. GUI and Threads
    By rp181 in forum Threads and Synchronization
    Replies: 1
    Last Post: 10-10-2009, 08:39 PM
  4. Using threads
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 12-11-2007, 10:25 AM
  5. Threads
    By one198 in forum Threads and Synchronization
    Replies: 1
    Last Post: 11-20-2007, 06:15 PM

Posting Permissions

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