Java ‘prototype’ mode – New vs clone vs class newInstance

In my project, some "prototype" factories create instances by cloning the final private instances

The authors of these factories say that this pattern provides better performance than calling the "new" operator

Using Google to get some clues, I didn't find anything related This is a small excerpt found by javdoc from an unknown project

To me, it looks like a best practice in the Java 1.1 era Does anyone know this better? Is this a good habit of using "modern" JVMs?

Solution

Of course, this approach is completely outdated Since then, the Java virtual machine has greatly improved Object creation is very cheap Another related practice, object pooling, is also obsolete because the cost of object creation and cleanup is now much higher In some cases, this may be useful (Jon skeet gives some good examples here), but it should never be part of such a basic framework library

I suggest finding some new libraries and / or a new project to work; -)

Check out this class article Java urban performance legends for more insights

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>