What is lazy loading


Answered by Nikhil on 2005-05-11 11:28:14: Lazy loading is a characteristic of an application when the actual loading and instantiation of a class is delayed until the point just before the instance is actually used. The goal is to only dedicate memory resources when necessary by only loading and instantiating an object at the point when it is absolutely needed. 
 
Tools such as Eclipse have popularized the lazy-loading approach as they use the facility to control the load and initialization of heavyweight plug-ins. This gives the double bonus of speeding up the initial load time for the application, as not all plug-ins are loaded straightaway; ensuring efficiency as only the plug-ins that are used are loaded at all.  

Showing Answers 1 - 2 of 2 Answers

Nikhil

  • May 11th, 2005
 

Lazy loading is a characteristic of an application when the actual loading and instantiation of a class is delayed until the point just before the instance is actually used. The goal is to only dedicate memory resources when necessary by only loading and instantiating an object at the point when it is absolutely needed. 
 
Tools such as Eclipse have popularized the lazy-loading approach as they use the facility to control the load and initialization of heavyweight plug-ins. This gives the double bonus of speeding up the initial load time for the application, as not all plug-ins are loaded straightaway; ensuring efficiency as only the plug-ins that are used are loaded at all.  

  Was this answer useful?  Yes

In Lazy loading, you load the child data as and when required.

Example:

public class OrderBean implements EntityBean {

        private long orderId;

        private String orderName;

        private long lineItemId;    // FK to the child table LineItems table   

        private Collection lineItems;    // child data from LineItems table

    public void ejbLoad() {

            // step1: select orderId, orderName and lineItemId from Order table

    }

    public Collection getLineItems(){

          /* step2: get lineItems by looking up LineItem entity bean

                       : look up LineItem home reference through JNDI

                       lineItems = lineItemHome.findLineItems(lineItemId);

         */

            return lineItems;

    }

Here you load the data as and when client calls getLineItems() but not when it calls other business methods. So Lazy loading is best to improve performance and use it when you implement relationships in Entity beans.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions