The essential difference between lazy and a hungry man in a single case

Source: Internet
Author: User

The essential difference between lazy and a hungry man in a single case lies in the following points:

1, a hungry man type is thread-safe, in the creation of a class at the same time has created a static object for the system to use, not change later. Lazy type If you create an instance object without adding synchronized, the access to the object is not thread-safe.

2, from the realization of their biggest difference is lazy-type is delayed loading, he is in need of time to create objects, and a hungry man-type in the virtual machine when the start will be created, a hungry man-style without attention to multithreading problems, simple and clear, can be used. But it is the instance that was created when the class was loaded (one of the friends wrote the wrong one), so if it is a Factory mode, caching a lot of instances, then you have to consider the efficiency problem, because this class one load will all the instances are created without using a block.

The essential difference between lazy and a hungry man in a single case

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.