Re: One thread per object
Patricia Shanahan wrote:
Mark Space wrote:
oliver.bayer@googlemail.com wrote:
Thomas Weidenfeller schrieb:
Implement the Runnable interface (which is anyhow considered to be the
cleaner way to use threads) for your class. Create a separate Thread
object for each Runnable instance of your class.
but I don't want to implement the Runnable interface. The objects I
describe could be every kind of object. I am looking for something like
a ThreadManager. I try to describe my problem more precise.
Consider some other design pattern beside inheritance. You could
encapsulate the the objects you want to run with aggregation, or
decorate them, or any number of things. The easiest might be just to
make a map with one object to run, and another Thread object that is
executing the object.
You still need some specification of what it means to "run" an object
that does not implement Runnable.
Patricia
Right-o. I assume the OP has some scheme in mind, he just hasn't given
us enough info to guess at what.
I'd use Object, and pair them up with a Thread or a Runable obeject.
When the Object is passed in to be run, I'd use some of the reflection
object to pass in with the Object, as a separate parameter, what method
exactly is to be run. With a little more reflection, the method could
be inspect and it's parameters could be determined, then take a SWAG at
what parameters should be at runtime.
That's the most general, basic thing I can think of. One Object to be
run, and the method to execute as a passed parameter.
Obviously some kind of formal Java Interface would be much better, but
the OP may be laboring under some heavy restrictions imposed by the
customer, and may not be able to refactor existing code.