Putting logic (especially expensive database or LDAP calls) inside a getter 
method is a bad practice. Everytime I do that, I run into the same problems as 
you do.

An option can be something like this:

class MyRequestBean {
    private List list;

    public List getList() {
        if (this.list == null) {
            this.list = someService.loadList();
        }
        return this.list;
    }
}

In some cases, you can put your stuff in a session (or application) scoped 
managed bean, which caches it for a longer time, making it more efficient. 
(except that there will be more memory footprint)

But usually, stay away from loading data in getters. Instead, use methods that 
are called more explicitly, like action(Listener)s or some kind of bean 
initialization method. That way, the behavior is much more predictable.

(or use a framework like Shale or Seam, which supports those kind of things out 
of the box)

Greets,

Jan-Kees van Andel


-----Original Message-----
From: Richard Yee [mailto:[EMAIL PROTECTED]
Sent: Thu 9/27/2007 2:14 PM
To: MyFaces Discussion
Subject: Re: Perfomance problem with JSF
 
How are you using your LDAP ArrayList? Should you be using a Map 
instead? Is the getter/setter in a ManagedBean or somewhere else? Are 
you doing more in your getter than just returning an instance variable?

Angel Miralles Arevalo wrote:
> Hi everybody, I have a perfomance problem with JSF. I have a 
> java arraList attribute. This attribute have getter and setter 
> methods. It is used to store LDAP users, so I have to access LDAP in 
> getter method.
>  
> Because of the lifecycle the getter is invoked twice, so LDAP access 
> is twice too. The problem is my LDAP has around 15000 users. My web 
> application is getting very slow.
>  
> How can I customize this behaviour??
>  
> Thanks in advanced.
>
> ------------------------------------------------------------------------
>
> Sé un Mejor Amante del Cine
> ¿Quieres saber cómo? ¡Deja que otras personas te ayuden! 
> <http://us.rd.yahoo.com/mail/es/tagline/beabetter/*http://advision.webevents.yahoo.com/reto/entretenimiento.html>.


Reply via email to