Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
but my question is we still have object alive which was pointing to Thread (with which we earlier called start() method and started the Thread). This object is still there in memory and is not garbage collected even after complete execution of thread. so again when i say threadObject.start() , shouldn't it start new Thread( )?
ok and my second question is why there is this difference between Thread and Runnable? why its that when we implement Runnable we can start thread again but the same is not possible if we extend Thread.
If you want to be able to restart your code, don't extend Thread, implement Runnable. - Peter
dan moore, infomatiq ltd.<br />email dan@infomatiq.co.uk<br /><a href="http://www.infomatiq.co.uk" target="_blank" rel="nofollow">http://www.infomatiq.co.uk</a>
If you want to be able to restart your code, don't extend Thread, implement Runnable. - Peter
It could behave like that, but then it would no longer be a simple abstraction of an operating system Thread. It would be (say) a ThreadRunner. Ultimately it's a design choice: Thread represents an OS thread.theoretically Thread could be defined to behave differently, so that a new thread (actual thread of execution, not a Thread instance) could be created if you called threadObject.start() again, but that is just not what happens. (there are probably some good reasons for this behaviour, i have not thought it through to be honest).
Peter den Haan | peterdenhaan.com | quantum computing specialist, Objectivity Ltd
Yeah, but is it art? What do you think tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|