Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Destroying a thread in a threadgroup

Reply
Thread Tools

Destroying a thread in a threadgroup

 
 
Frank Cisco
Guest
Posts: n/a
 
      06-02-2009
How do you destroy a thread in a ThreadGroup? What I want to do is put a
timer on each thread and if any don't return in say 30 seconds then destroy
the thread. I've tried adding a seperate timer thread to each running thread
but it's too memory intensive. Also the ThreadGroup won't allow direct
access to it's threads - it seems to make a copy of the threads?


 
Reply With Quote
 
 
 
 
Mark Space
Guest
Posts: n/a
 
      06-02-2009
Frank Cisco wrote:
> How do you destroy a thread in a ThreadGroup? What I want to do is put a
> timer on each thread and if any don't return in say 30 seconds then destroy
> the thread. I've tried adding a seperate timer thread to each running thread
> but it's too memory intensive. Also the ThreadGroup won't allow direct
> access to it's threads - it seems to make a copy of the threads?
>
>


Who writes the thread code? You or someone else?

If it's you, you can control what happens when the thread is running and
you can therefore be assured what will happen when you call a method to
stop it. Thread stop() works, but is deprecated. I think however it
would be ok to call Thread stop() if you knew there were no resources
that would leak as a result.

Setting a flag or calling Thread interrupt() are less intrusive ways to
stop a thread, especially if you are dealing with IO (which would leak
resources if you call Thread stop()).

The Executor service mentioned by Zig just uses interrupt() or waits for
a thread to terminate on it's own, there's no magic there. An Executor
will not forcibly stop a thread due to the potential for resource leaks.
You have to write your thread code to respond to an interrupt(), or
the thread will always run to completion.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Threads in a threadgroup Crouchez Java 3 11-06-2007 03:00 PM
question about "active thread in ThreadGroup" emily.ranyu@gmail.com Java 1 06-05-2006 05:06 AM
Problem wtih Java ThreadGroup.activeCount method avinashrk Java 10 12-14-2004 05:54 PM
Stopping a ThreadGroup Timo Nentwig Java 4 10-25-2003 04:25 PM
ThreadGroup#enclose Dave Thomas Ruby 2 08-05-2003 07:45 PM



Advertisments