Is there an alternative to extending class Thread for producing threadable code? If there is what does it require?
Printable View
Is there an alternative to extending class Thread for producing threadable code? If there is what does it require?
Yes, you could not extend it, but use it as-is passing an instance of Runnable to its constructor. See Defining and Starting a Thread in Oracle's Tutorial.Quote:
Is there an alternative to extending class Thread for producing threadable code?
That section of the Tutorial also discusses using Executor interfaces - again pass them a Runnable and it gets run. The Executor may well do things like maintain pools or worker threads (so you don't have to).