Tuesday 15 April 2014

java - dynamic vs lazy loading -


I only knew about the dynamic proxy used for AOP.
However, it can also be used for lazy loading. The purpose of the following example from an article is to demonstrate it.
Still, I am unable to understand why this is different from the normal accessor and actually 'lazy' is filled up? Due to lazy-loading, the author is appreciated what it means.

  Private class tubalobject (serializable [] tubal) {category category = new category (string) taple [1], (year old) tuple [2]); Category.setId (Long) Tuple [0]); Category.setParent (Lazy Tulle [3])); Return range; } Secure range ITF lazy (long ID) {if (id == null) {return null; } Return (Category ITF) Proxy NAPProxy instance (category ITF class.gate class loader ()), new class [] {class ITF. Class}, new lesliedodject () {secure object load object () {return find (id);}}); } Public Essentials LazyLoadedObject invocationHandler {Private object target; Call of Public Object (Object Proxy, Method Method, Object [] AGR) Throws throws (if (target == empty) {target = loadObject ();} Return method.invoke (target, args);} Secure abstract object loadObject ();}   

How can it be that one of the following is different:

  private class tupleToObject (serializable [] tople) {category category = New category (String) Tupal [1], (Ermanthhede) Tuple [2]); Category.setId (Long) Tuple [0]); Category.setParent (Received Do (Long) Tupal [3])); Return range; }   

In both cases, parents are required only when necessary.

The following code snippet implementation makes "lazy":

  private Object target; Public Object Call (Object Proxy, Method Method, Object [] AGR throws throws if you (target == empty) {target = loadObject ();}   

You can see That's how many times you are calling this code, you get the same object every time. So, this is practically a single, though it has not been made at the beginning of the program but only when it is needed for the first time. The meaning of "lazy" The An.

No comments:

Post a Comment