start join start

R

Ravi

Can you please tell why the following code snippet gives me error
IllegalThreadStateException

n1 = new Thread(......//
n2 = new Thread(......//
...
//
n1.start();
n2.start();

n1.join();
n2.join();

n1.start();
n2.start();

....
 
E

Eric Sosman

Ravi wrote On 03/06/07 12:32,:
Can you please tell why the following code snippet gives me error
IllegalThreadStateException

n1 = new Thread(......//
n2 = new Thread(......//
..
//
n1.start();
n2.start();

n1.join();
n2.join();

n1.start();
n2.start();

Because a Thread can only be started once. Read the
Javadoc.
 
T

Thomas Schodt

Ravi said:
but can we stop and then start it again.any work around for it

Tell us what you are trying to accomplish.

Is there a reason for not using new Thread() again?

[A workaround would be; don't allow the thread to complete in the first
place.]
 
P

Patricia Shanahan

Ravi said:
but can we stop and then start it again.any work around for it

You have two options:

1. Use some form of coordination other than join, so that each thread
does not terminate until it has done all its work.

2. Create new threads to do the post-join tasks.

Patricia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top