Threads should not be Cloneable

David Holmes David.Holmes at oracle.com
Sun Aug 15 22:22:13 UTC 2010


Hi Florian,

Florian Weimer said the following on 08/15/10 21:51:
> * David Holmes:
>> 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?
> 
> Increased backwards compatibility.

The only thing this would increase compatibility with is if there exists 
already a subclass of Thread that overrides clone() to provide 
construction-based cloning**. Are you aware of such a use-case? The 
postings to the concurrency-interest mailing list and to here are to 
solicit feedback regarding any genuine use-cases for this functionality. 
So far there have been (as we expected) zero responses regarding actual 
use.

The 'final' makes it clear that the programmer should just forget about 
clone() when it comes to Thread and any of its subclasses. If we remove 
the final then we have to provide additional documentation explaining 
the limitations that any override of clone() would encounter.

** Any usage involving super.clone() is already affected by this change 
regardless of 'final'.

Cheers,
David Holmes



More information about the core-libs-dev mailing list