• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threadgroups, must extend Thread?  RSS feed

 
Ed M
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a class which I want to run as a thread. I would like that thread to implement Runnable rather then extend Thread so that I can extend from another object. (fyi, This thread is being created by another thread.)
The problem I have is that I need this thread to run withing a group. The only way I can get this to work is by extending Thread and calling super(group,threadname) in the construtor...(of course the object which creates this thread passed in the thread group and name).
Is there another way I can place this thread in a group beside using the constructor?
Thanks, ed
 
Blake Minghelli
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use this constructor:
Here is some sample code of how I do it:

That code starts 5 Runnable objects as threads and assigns them to one ThreadGroup.
Hope that helps
 
Leslie Chaim
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ed M:
I created a class which I want to run as a thread. I would like that thread to implement Runnable rather then extend Thread so that I can extend from another object.

Ed, welcome to the ranch I'll let the Shrifts enforce the naming policy :roll:
A thread, strictly speaking, is merely a path of execution. That said, a thread does not implement Runnable rather a class does. Also, a class does not run as a thread rather it HAS A thread or IS A thread. These are academic discussions but correct terminology is important.
On to your problem, and if I understand you correctly you would do something like this:

BTW, There is no method to move a thread into a particular group.
I hope that I understood your original questions and that this Helps
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll let the Shrifts enforce the naming policy

Ed, "M" is isn't quite what we consider a valid last name; it falls in the category of "obviously fictitious". Please check out our display name policy and modify your display name accordingly. Thanks.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!