Jump to content

IllegelThreadState exception

- - - - -

  • Please log in to reply
3 replies to this topic

#1
eman ahmed

eman ahmed

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
my program doesn't work correctly because this exception

while(count<sharedBetweenThreads.size()){

                for (int i = 0; (i < ourThreads.length)

                        && count < sharedBetweenThreads.size(); i++) {

                    if (ourThreads[i].isAlive() == false) {

                       

                        ourThreads[i].start();


                    }

                }

if the length of an array of threads(ourthreads) equal 2.
the two threads start and then the program check the while condition and if it's true
he check if ourThreads[i].isAlive() == false and then the thread must start
but unfouretantly ,it's throw this exception

please how can I solve this problem

#2
Metalhead

Metalhead

    Newbie

  • Members
  • PipPip
  • 27 posts
You can never start a Thread twice.
A thread-instance can only run once, then it's dead.

You need to create a new Thread and start that.
Usually you want to use the Runnable for something like this.

public class YourClass implements Runnable {....}

// To use it;
...
Thread t = new Thread(new YourClass());
t.start();
...


#3
eman ahmed

eman ahmed

    Learning Programmer

  • Members
  • PipPipPip
  • 79 posts
I tried this but unfourtanitly it doesn't work and I'm still have the same problem
can anybody help me?

#4
eafkuor

eafkuor

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 218 posts
You just start the threads once and let them run.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users