Illegela thread operation...?
Hello,
I have a class like that:
class Sampleimplements Runnable{
privateint x = 0;
publicsynchronizedvoid run(){
for (int i=0;i<10;i++){
try{
Thread.sleep(100);
}catch (InterruptedException ex){
}
x++;
System.out.println(Thread.currentThread().getName() +" : " + x);
}
}
}
And I consume this class like that:
Sample s =new Sample();
Thread t1 =new Thread(s);
t1.setName("First");
Thread t2 =new Thread(s);
t2.setName("Second");
System.out.println("STARTING");
t1.start();
t2.start();
t2.join();
System.out.println("END");
When I execute this code, I sometimes get this error:
java.lang.IllegalThreadStateException
at java.lang.ThreadGroup.add(ThreadGroup.java:846)
at java.lang.Thread.start(Thread.java:596)
What is the wrong with the threads that I create?
Thanks in advance...

