2

Possible Duplicate:
Terminated Thread Revival

 Thread threadWait = new Thread()
    {
        @Override
        public void run() {
            try {
                sleep(10000);
                sync = false;
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }               
    };

I call this thread here:

            threadWait.start();
        while(sync){
        //do something
        }

when threadWait finished the state is TERMINATED. How i can start the thread another time? Any idea? THX TO ALL!

SOLUTION:

Runnable runWait = new Runnable(){
    public void run(){
        try {
            Thread.sleep(10000);
            sync = false;
        } catch (InterruptedException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
};

and..

Thread first = new Thread(runWait);
            first.start();
Community
  • 1
  • 1

2 Answers2

1

You cannot start the same Thread object several times. Just create new Thread and start it.

olshevski
  • 4,971
  • 2
  • 35
  • 34
1

How i can start the thread another time?

You can't. Any thread can only be run once. Of course, you can create a new Thread with the same Runnable if you want, and start that second thread...

Runnable runnable = new Runnable() {
    // Code as before
};
Thread first = new Thread(runnable);
first.start();
... Maybe the first thread dies...
Thread second = new Thread(runnable);
second.start();
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194