Threads should not be Cloneable
David Schlosnagle
schlosna at gmail.com
Sat Aug 14 00:24:37 UTC 2010
On Fri, Aug 13, 2010 at 7:21 PM, David Holmes <David.Holmes at oracle.com> wrote:
> tom.hawtin at oracle.com said the following on 08/14/10 00:12:
>>
>> On 13/08/2010 14:58, Chris Hegarty wrote:
>>
>>> protected final Object clone() throws CloneNotSupportedException {
>>> throw new CloneNotSupportedException();
>>
>> The final can (and should, IMO) be removed.
>
> Why? What purpose would it serve?
>
> You can not clone the Thread. The "clone" of the subclass could only be done
> via construction - so just use a constructor in the first place. As David
> Schlosnagle points out any subclass of that "Cloneable" would have to use a
> similar construction-based clone because super.clone() can not return the
> correct type. That's a bug waiting to happen.
>
> Why given even the smallest illusion that a Thread subclass can be cloned?
>
> David
>
In addition to making Thread.clone() final and throw
CloneNotSupportedException, it would be nice to add @Deprecated so
callers will show up as a compiler warning and in IDEs, as well as
join the ranks of all the other deprecated Thread methods.
- Dave
More information about the core-libs-dev
mailing list