> I need to restart a Java Thread in my application. what would be the
> safe way of doing this.

Signature
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
>> I need to restart a Java Thread in my application. what would be the
>> safe way of doing this.
[quoted text clipped - 3 lines]
> "It is never legal to start a thread more than once. In particular, a
> thread may not be restarted once it has completed execution."
Does legal mean the code won't compile or that it just isn't good
practice? I ask because I have a class that contains a run() for a
thread and I call it everytime I need to do the operation that the run()
performs and I do so w/o creating a new instant of the class that the
run() is a part of. So far I haven't seen any problems with that
approach. Is that not the same thing as what the original poster was
trying to do?
> You have lots of choices to get the effect you want. You can
> create new threads to pick up where the dead threads leave off; better
[quoted text clipped - 4 lines]
> come nicely wrapped with love from Sun - you'll have to write
> something to suit your needs yourself.
Karl Uppiano - 28 Oct 2006 03:44 GMT
> Does legal mean the code won't compile or that it just isn't good
> practice? I ask because I have a class that contains a run() for a thread
> and I call it everytime I need to do the operation that the run() performs
> and I do so w/o creating a new instant of the class that the run() is a
> part of. So far I haven't seen any problems with that approach. Is that
> not the same thing as what the original poster was trying to do?
Legal in the sense that it won't work. If you create a new thread and start
it, when it finishes running whatever top level run() method you give it,
and that run() method returns, that thread is finished and it will not
restart, no matter what you do. You will have to create a new one. You can
create new threads all day long, and give them the same old run() method the
same old instance, that works just fine. But the thread dies when run()
returns, and it cannot be revived.
Mike Schilling - 28 Oct 2006 18:48 GMT
>>> I need to restart a Java Thread in my application. what would be the
>>> safe way of doing this.
[quoted text clipped - 6 lines]
> Does legal mean the code won't compile or that it just isn't good
> practice?
That it won't work.
> I ask because I have a class that contains a run() for a thread and I call
> it everytime I need to do the operation that the run() performs and I do
> so w/o creating a new instant of the class that the run() is a part of.
But you're not creating a thread when you do that; you're just calling a
method. If you called "start()" repeatedly on a Thread (or subclass of
Thread), then you'd see it fail after the first time.